module confusion

Steve Holden steve at holdenweb.com
Fri Oct 5 13:37:34 CEST 2007


Steven D'Aprano wrote:
> On Fri, 05 Oct 2007 00:12:33 -0500, Robert Kern wrote:
> 
>> This is somewhat odd, because most modules aren't exposed that way. They
>> are either in their own file and accessed by importing them directly, or
>> they are inside a package.
> 
> Any time you say:
> 
> import parrot
> 
> 
> in one of your modules, you export parrot to anything that 

subsequently

>                                                              imports your 
> module. (Unless you take specific steps to prevent it, for instance with 
> del parrot.)

or the creation of an __all__ containing an exclusive list of names for 
export.
> 
> 
> Just to pick some random examples:
> 
>>>> import ConfigParser, base64, fileinput
>>>> ConfigParser.re
> <module 're' from '/usr/lib/python2.5/re.pyc'>
>>>> base64.struct
> <module 'struct' from '/usr/lib/python2.5/struct.pyc'>
>>>> base64.binascii
> <module 'binascii' from '/usr/lib/python2.5/lib-dynload/binascii.so'>
>>>> fileinput.sys
> <module 'sys' (built-in)>
>>>> fileinput.os
> <module 'os' from '/usr/lib/python2.5/os.pyc'>
> 
> 
> It's quite common.
> 
> 
OK, I am sort of getting used to the idea that you guys are going to 
beat this one to death with a stick, and will still be tossing emails 
back and forth to each other while the rest of us are admiring the heat 
death of the universe.

So please try and avoid writing anything that will be misconstrued by 
newless cloobs unfortunate enough to reach this thread as a result of a 
search for meaningful information on Python imports.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline so I couldn't cat it




More information about the Python-list mailing list