[Tutor] Error while using calendar module in Python 2.7

ranjan das ranjand2005 at gmail.com
Sat Mar 5 08:52:42 CET 2011


Please consider this corrected  example


The correctly indented code with the while loop is


while monday.weekday() != calendar.MONDAY:
       MONDAY -= oneday


oneweek = datetime.timedelta(days=7)

nextweek = today + oneweek

nextyear = today.replace(year=today.year+1)

print "Today (year-month-day) =", today
print "Most recent Monday =", monday



On Sat, Mar 5, 2011 at 1:20 PM, ranjan das <ranjand2005 at gmail.com> wrote:

> Sorry David
>
>
>
>
>
>
> Is there any change in the calendar module from Python 2.6 to 2.7.
>
> This example works fine in Python 2.6 but throws up an error in 2.7
>
>
>
> On Sat, Mar 5, 2011 at 12:58 PM, David Hutto <smokefloat at gmail.com> wrote:
>
>> Could you paste the whle code, because I get:
>>
>> >>> import datetime
>> >>> import calendar
>> >>>
>> >>>
>> >>>
>> >>> while monday.weekday() != calendar.MONDAY:
>> ...
>>  File "<stdin>", line 2
>>
>>    ^
>> IndentationError: expected an indented block
>> >>>     monday -= oneday
>>  File "<stdin>", line 1
>>    monday -= oneday
>>    ^
>> IndentationError: unexpected indent
>> >>>
>> >>> oneweek = datetime.timedelta(days=7)
>> >>>
>> >>> nextweek = today + oneweek
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> NameError: name 'today' is not defined
>> >>>
>> >>> print next week
>>
>
>
>
> --
> The inherent vice of capitalism is the unequal sharing of blessings; the
> inherent virtue of socialism is the equal sharing of miseries.
>
> ~ Winston Churchill
>



-- 
The inherent vice of capitalism is the unequal sharing of blessings; the
inherent virtue of socialism is the equal sharing of miseries.

~ Winston Churchill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110305/43a2c68f/attachment.html>


More information about the Tutor mailing list