Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > from calendar import* doesn't import everything

Reply
Thread Tools

from calendar import* doesn't import everything

 
 
Rotwang
Guest
Posts: n/a
 
      04-24-2012
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'>

?

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

http://tinyurl.com/psymix
 
Reply With Quote
 
 
 
 
Justin Ezequiel
Guest
Posts: n/a
 
      04-24-2012
see
http://docs.python.org/tutorial/modu...from-a-package
http://stackoverflow.com/questions/2...l-variable-for

I know the 1st link is for importing from a package but the same
applies for modules
 
Reply With Quote
 
 
 
 
Rotwang
Guest
Posts: n/a
 
      04-24-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
 
Reply With Quote
 
Rotwang
Guest
Posts: n/a
 
      04-25-2012
On 25/04/2012 01:26, Kiuhnm wrote:
> [...]
>
> 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.


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

http://tinyurl.com/psymix
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not Quite Everything for a Theory of Everything fitz VOIP 0 02-28-2010 04:42 PM
why not import everything? yawnmoth Java 42 02-21-2009 03:00 AM
Thunderbird Calendar with Exchange 2003 Calendar and Public FoldersCalendar jincmcse Firefox 1 09-03-2005 02:46 AM
How do I import everything in a subdir? Dfenestr8 Python 5 03-07-2005 09:24 AM
Calendar Control - Programatically set the calendar to a date range Shevek ASP .Net 3 06-23-2004 01:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57