[Tutor] Getting error that calendar is underfined when importing calendar module

2005-03-23 Thread Vicki Stanfield
Hi all. I am using Python 2.4 on a Slackware Linux box and am having a
problem importing the calendar module into a program that I am writing.
The code is simple and looks like this:

import cgitb, os, sys
cgitb.enable()
sys.strerr = sys.stdout

import cgi
import time
import calendar

print Content-Type: text/html\n\n
print
print htmlhead/headbody\n\n

#Get date variables
from datetime import datetime
date = datetime.now().date()
today= date.strftime(%m %Y)
thisyear = date.strftime(%Y)
thismonth = date.strftime(%m)

#Print calendar for the current month
calendar.prmonth(int(thisyear),int(thismonth))

-
For some reason that I don't understand, I get an error when I use this
code in a cgi way (run the file out of cgi-bin) but not when I type it
from the command line. The error I get is this:

 /var/www/cgi-bin/calendar.py
   43 calendar.prmonth(int(thisyear),int(thismonth))
calendar = module 'calendar' from '/var/www/cgi-bin/calendar.py',
calendar.prmonth undefined, builtin int = type 'int', thisyear = '2005',
thismonth = '03'

AttributeError: 'module' object has no attribute 'prmonth'
  args = ('module' object has no attribute 'prmonth',)

The calendar module description says there is a prmonth, and as I said, it
works from the command line. Can anyone tell me what I am missing?

Vicki

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting error that calendar is underfined when importing calendar module

2005-03-23 Thread Kent Johnson
The cgi is importing itself when you 'import calendar'. Try renaming your calendar.py to something 
else like calendar-cgi.py

Kent
Vicki Stanfield wrote:
Hi all. I am using Python 2.4 on a Slackware Linux box and am having a
problem importing the calendar module into a program that I am writing.
The code is simple and looks like this:
import cgitb, os, sys
cgitb.enable()
sys.strerr = sys.stdout
import cgi
import time
import calendar
print Content-Type: text/html\n\n
print
print htmlhead/headbody\n\n
#Get date variables
from datetime import datetime
date = datetime.now().date()
today= date.strftime(%m %Y)
thisyear = date.strftime(%Y)
thismonth = date.strftime(%m)
#Print calendar for the current month
calendar.prmonth(int(thisyear),int(thismonth))
-
For some reason that I don't understand, I get an error when I use this
code in a cgi way (run the file out of cgi-bin) but not when I type it
from the command line. The error I get is this:
 /var/www/cgi-bin/calendar.py
   43 calendar.prmonth(int(thisyear),int(thismonth))
calendar = module 'calendar' from '/var/www/cgi-bin/calendar.py',
calendar.prmonth undefined, builtin int = type 'int', thisyear = '2005',
thismonth = '03'
AttributeError: 'module' object has no attribute 'prmonth'
  args = ('module' object has no attribute 'prmonth',)
The calendar module description says there is a prmonth, and as I said, it
works from the command line. Can anyone tell me what I am missing?
Vicki
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting error that calendar is underfined when importing calendar module

2005-03-23 Thread Vicki Stanfield
 The cgi is importing itself when you 'import calendar'. Try renaming your
 calendar.py to something
 else like calendar-cgi.py

 Kent

Thanks. I was almost there, having noticed that dir(calendar) was
different when run from the script than in an interactive session.

Vicki

P.S. Now to parse the data.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor