On Tue, Nov 10, 2009 at 2:02 PM, MRAB <pyt...@mrabarnett.plus.com> wrote:
> Victor Subervi wrote: > >> Hi; >> I have the following code: >> >> import calendar, datetime >> >> def cal(): >> ... >> myCal = calendar.Calendar(calendar.SUNDAY) >> today = datetime.date.today() >> day = today.day >> mo = today.month >> yr = today.year >> # month = myCal.monthdayscalendar(int(time.strftime("%Y")) >> month = myCal.monthdayscalendar(yr, mo) >> print 'hi' >> >> html headers are included. No matter which one of the last two lines I >> comment out, I never get to the point of printing 'hi'. (If I comment them >> both out, it does print.) What do? >> >> Read the tracebacks? > > The commented line will raise an exception because: > > 1. There's a final ')' missing. > > 2. You haven't imported 'time'. > > 3. .monthdayscalendar() requires the year and month. > > I don't know why you're writing 'int(time.strftime("%Y"))' because you > already have the year in 'yr'. > > The code above works for me if I comment out the line '...'. > -- > <http://mail.python.org/mailman/listinfo/python-list> It works fine for me in the python interpreter but not in the page from which it's called! You say import time, but where do I call time in my script? Here's the code (abbreviated just to print something out to see it work), please advise if you can: #!/usr/bin/python import string import sys,os sys.path.append(os.getcwd()) import calendar, datetime, time import MySQLdb import string, re from login import login def calendarPrint(): print "Content-Type: text/html" print print """ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <head xmlns="http://www.w3.org/1999/xhtml"> <style type='text/css'> .text { font-family: Arial, Helvetica, sans-serif; font-size: 16px; text-decoration: none; text-align: justify } </style> <title>NR Electric</title> <meta http-equiv="distribution" content="Global" /> <meta http-equiv="robots" content="index all, follow all" /> </head> <body> <script language="JavaScript1.2" src="wz_tooltip.js" type="text/javascript"></ script> """ myCal = calendar.Calendar(calendar.SUNDAY) today = datetime.date.today() day = today.day mo = today.month yr = today.year month = myCal.monthdayscalendar(yr, mo) print month calendarPrint()
-- http://mail.python.org/mailman/listinfo/python-list