Link to home
Start Free TrialLog in
Avatar of jameskane
jameskane

asked on

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 !!

James
languageERROR.jpg
ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clockwatcher
clockwatcher

BTW... with regards to the error that you're getting, you might want to think about using the cgitb module (https://docs.python.org/2/library/cgitb.html) 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
cgitb.enable()

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.
Avatar of jameskane

ASKER

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 .

James


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

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

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





#main program
if __name__== "__main__":
    try:
        htmlTop()
        print("james")
        
        currentyear = datetime.datetime.now().year
        print(currentyear)
        currentmonth = datetime.datetime.now().month
        currentday = datetime.datetime.now().day
        print(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)
            
                    
       
        
        
        htmlTail()
    except:
        cgi.print_exception()

Open in new window

Thanks very much !