On 4/25/2012 1:54, Rotwang wrote:
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?

Let's see... at line 561 of calendar.py there's something suspicious:

--->
# Support for old module level interface
c = TextCalendar()

firstweekday = c.getfirstweekday

def setfirstweekday(firstweekday):
    try:
        firstweekday.__index__
    except AttributeError:
        raise IllegalWeekdayError(firstweekday)
    if not MONDAY <= firstweekday <= SUNDAY:
        raise IllegalWeekdayError(firstweekday)
    c.firstweekday = firstweekday

monthcalendar = c.monthdayscalendar
prweek = c.prweek
week = c.formatweek
weekheader = c.formatweekheader
prmonth = c.prmonth
month = c.formatmonth
calendar = c.formatyear
prcal = c.pryear
<---

So, it seems that "from calendar import *" is reserved for the "old interface" (i.e. non-OO).

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

Reply via email to