Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Calendar Stuff

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


victorsubervi at gmail

Nov 10, 2009, 9:53 AM

Post #1 of 6 (271 views)
Permalink
Calendar Stuff

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?
TIA,
Victor


python at mrabarnett

Nov 10, 2009, 11:02 AM

Post #2 of 6 (252 views)
Permalink
Re: Calendar Stuff [In reply to]

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


victorsubervi at gmail

Nov 10, 2009, 11:58 AM

Post #3 of 6 (252 views)
Permalink
Re: Calendar Stuff [In reply to]

On Tue, Nov 10, 2009 at 2:02 PM, MRAB <python [at] mrabarnett> 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()


davea at ieee

Nov 10, 2009, 1:05 PM

Post #4 of 6 (246 views)
Permalink
Re: Calendar Stuff [In reply to]

(Comments inline, and at end)

Victor Subervi wrote:
> On Tue, Nov 10, 2009 at 2:02 PM, MRAB <python [at] mrabarnett> 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!
Then why didn't you say so, and in particular mention that this is a
problem only when running on a webserver as a cgi program? And give the
error message, and examine the server's log file, and ...

> You say import time, but where do I call time in my
> script?
On the commented line with the call to time.strftime(), that looks to
me like a ref to the time module. You said in your original message
that it fails whichever of the last two lines is commented out...
well one reason it would fail is no import of time.

> 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>
>
>
You can't break apart the </script> The slash must appear directly
before the '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()
>
>
I haven't tried to upload it to a server. But running it locally, then
taking the output and feeding it to Firefox, I see a few things wrong.
It's declared asw HTML, but you don't have a <html> opening tag. And
you're missing closing tags for /body and /html Tidy complains that
the DOCTYPE url is malformed, but you couldn't prove it by me.

And month is a list of lists, so I don't know why you're printing it.

DaveA
--
http://mail.python.org/mailman/listinfo/python-list


sajmikins at gmail

Nov 10, 2009, 10:12 PM

Post #5 of 6 (241 views)
Permalink
Re: Calendar Stuff [In reply to]

On Tue, Nov 10, 2009 at 12:53 PM, Victor Subervi
<victorsubervi [at] gmail> 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?
> TIA,
> Victor

Have you tried walking through the code line-by-line in the
interactive interpreter?

That should give you an idea of why those lines aren't working. Also,
if your code never prints 'hi', what does it do instead? Hang? Or
give you a traceback?
--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 11, 2009, 5:23 AM

Post #6 of 6 (235 views)
Permalink
Re: Calendar Stuff [In reply to]

On Wed, Nov 11, 2009 at 1:12 AM, Simon Forman <sajmikins [at] gmail> wrote:

> On Tue, Nov 10, 2009 at 12:53 PM, Victor Subervi
> <victorsubervi [at] gmail> 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?
> > TIA,
> > Victor
>
> Have you tried walking through the code line-by-line in the
> interactive interpreter?
>

Yes. It works just fine in the interactive interpreter, darn it.

>
> That should give you an idea of why those lines aren't working. Also,
> if your code never prints 'hi', what does it do instead? Hang? Or
> give you a traceback?
>

Hangs. I'd love a traceback!
V

> --
> http://mail.python.org/mailman/listinfo/python-list
>

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.