from calendar import* doesn't import everything

R

Rotwang

Sorry if this is a stupid question, but what is up with this:

Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
Calendar
NameError: name 'Calendar' is not defined<class 'calendar.Calendar'>

?
 
R

Rotwang

Sorry if this is a stupid question, but what is up with this:


Traceback (most recent call last):
File "<pyshell#9>", line 1, in<module>
Calendar
NameError: name 'Calendar' is not defined
<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?
 
R

Rotwang

[...]

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).

Thanks, and likewise to Justin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top