importing question ?

Robin Munn rmunn at pobox.com
Mon Dec 2 12:46:41 EST 2002


Kenny Tilton <ktilton at nyc.rr.com> wrote:
> 
> 
> Kenny Tilton wrote:
>> 
>>> 'from classes import *' brings all the toplevel objects in classes 
>>> into your local namespace, so you can access them just through the 
>>> name. Generally, though, I think this is considered bad practice, as 
>>> it could create overlaps. 
>> 
>> 
>> I just ran into this and I do not like it, because I have what I 
>> consider one little subsystem (Cells) but I have it spread over ten 
>> source files. 
> 
> I just saw the option to:
> 
>    from <package> import *
> 
> along with listing all modules in an __all__ definition in the __init__ 
> file in the package directory. hope eternal. but it seems I then have to 
> qualify any reference with the module name (which I think I grok--it is 
> importing everything into the current namespace in go (nice) but then 
> leaves them compartmented by module when it does so (not what I wanted, 
> viz, a flat namespace for the package).

You might try looking at some of the larger packages that do tricks with
the 'import' module to get what they want. Try looking at the source for
wxPython, say, or the mx suite of modules. Some of those might give you
some ideas for how to write your __init__.py file -- there's lots of
options to try.

I'm sorry I can't be more specific here, but I haven't taken a specific
detailed look to learn packaging tricks yet, so others will have to give
you more detailed answers if you run into problems.

-- 
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838    50FF 2478 CFFB 081A 8338  54F7 845D ACFD 6AFB 6838



More information about the Python-list mailing list