[Tutor] Error while using calendar module in Python 2.7

David Hutto smokefloat at gmail.com
Sat Mar 5 08:37:44 CET 2011


>>>
>>> while monday.weekday() != calendar.MONDAY:
...     monday -= oneday
...     oneweek = datetime.timedelta(days=7)
...     nextweek = today + oneweek
...     print "next week"
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'monday' is not defined
>>>

This means that calender doesn't have an Monday as something you can
access. Look at how you use datetime.timedelta(days=7). If you type
help (datetime), you can see that timedelta is a function you can
access from datetime. However your utilization of calendar doesn't
align with the other. Look at the difference in each using the help
function(datetime.timedelta and calendar.MONDAY).

Also the error you show is a little confusing, because it looks like
you were trying calendar.FRIDAY instead of calendar.MONDAY at that
point.


More information about the Tutor mailing list