from calendar import* doesn't import everything

Rotwang sg552 at hotmail.co.uk
Tue Apr 24 19:54:40 EDT 2012


On 25/04/2012 00:42, Kiuhnm wrote:
> On 4/25/2012 1:18, Rotwang wrote:
>> Sorry if this is a stupid question, but what is up with this:
>>
>>   >>>  from calendar import*
>>   >>>  Calendar
>>
>> Traceback (most recent call last):
>> File "<pyshell#9>", line 1, in<module>
>> Calendar
>> NameError: name 'Calendar' is not defined
>>   >>>  from calendar import Calendar
>>   >>>  Calendar
>> <class 'calendar.Calendar'>
>>
>> ?
>
> calendar.py defines __all__ this way:
>
> __all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
>             "firstweekday", "isleap", "leapdays", "weekday", "monthrange",
>             "monthcalendar", "prmonth", "month", "prcal", "calendar",
>             "timegm", "month_name", "month_abbr", "day_name", "day_abbr"]
>
> Only those names are imported with '*'.
>
> Kiuhnm

Oh, I didn't realise modules could do that. Thanks.

Do you know what the rationale behind not including 'Calendar' is?

-- 
Hate music? Then you'll hate this:

http://tinyurl.com/psymix



More information about the Python-list mailing list