Python timestamp

I am trying to create a French time stamp using the Python 'datetime' modulle.  So instead of, for example, I need 25 juillet, 2015 vrs
July 25, 2015. The following code ALMOST does it. It picks up that today is July 25  and gives me a printout  25 Juillet , 2015.  The really weird thing is that the code does not work if I include MORE THAN 5 if statements. On adding a 6th it throws an error (image attached)
Obviously I need 12 if statements to cover janvier, février, mars, avril, mai, juin, juillet, août, septembre, octobre, novembre, décembre.

WING IDE  does not give any information on the error. It indicates that the error is outside the range of its competency.

Hopefully the problem is obvious to someone !!

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

We'd have to see your code to have any idea why you might be getting an error.  The screenshot you posted could mean anything.  

But, why would you need to use any if statements at all.  Use an array, with your month names and simply index into it using the month number...
import datetime
today =
months = ('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre')
print("{month} {day}, {year}".format(month=months[today.month-1],, year=today.year))

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BTW... with regards to the error that you're getting, you might want to think about using the cgitb module ( while you're developing your code.  It will make tracking down errors while you're developing your cgi scripts much easier.  Add the following to the start of your cgi code.
import cgitb

Open in new window

You typically wouldn't want to include it any production code as it may/will give out more information than someone visiting your website should see, but it should help as you develop and test your page.
jameskaneAuthor Commented:
Thanks very much clockwatcher.

The array approach looks great and I am going to try and use it !!

But could you take a quick look at the code, attached anyhow. Would like to understand the problem. Don't waste time if the problem does not jump out at you .


import cgi,cgitb
import mysql.connector as conn
import collections
import datetime
def htmlTop():
        <!DOCTYPE html>
        <html lang="en">
                <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
                <title> My Server-side template</title>

def htmlTail():
    print(""" its done</body>

def connectDB():
    db=conn.connect(host='localhost' ,user='root' ,passwd='844cheminduplan' ,db='office')
    cursor = db.cursor()
    return db, cursor

#main program
if __name__== "__main__":
        currentyear =
        currentmonth =
        currentday =
        if currentmonth == 3:
            lettermonth = "Mars"         
            print(currentday,lettermonth, "," ,currentyear)         
        if currentmonth == 4:
            lettermonth = "Avril"         
            print(currentday,lettermonth, "," ,currentyear)        
        if currentmonth == 5:
            lettermonth = "Mai"         
            print(currentday,lettermonth, "," ,currentyear)
        if currentmonth == 6:
            lettermonth = "Juin"         
            print(currentday,lettermonth, "," ,currentyear) 
        if currentmonth == 7:
            lettermonth = "Juillet"         
            print(currentday,lettermonth, "," ,currentyear)

Open in new window

jameskaneAuthor Commented:
Thanks very much !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.