Problem with packages and modules

Philip Swartzleonard starx at pacbell.net
Wed Apr 10 02:32:00 EDT 2002


Jørgen Hansen || Tue 09 Apr 2002 11:07:37p:

> Max M <maxm at mxm.dk> wrote in message news:<3CB2FA14.1050708 at mxm.dk>...
>> Jørgen Hansen wrote:
>> 
>> > This is an example of directory hierachy:
> <snip example hierachy>
[ Snip some other stuff ]
>> > Further if I typed in:
>> >    >>> import company
>> > 
>> > I would assume that I could access all subpackages and their
>> > modules with a dotted name (company.plot.figure.Figure() for
>> > instance), but this is obviously not the case.
>> >
>> 
>> You would need to import the modul in company/__init__.py:
>> import plot
>> 
>> to do:
>> 
>> import company
>> fig = company.plot.figure.Figure()
>> 
>> 
>> Hmm... I hope this helps a bit.
> 
> It does. Thanks a lot. After I wrote, I got thinking, that my approach
> would have meant that I would import the entire hierachy. Not very
> smart if the hierachy, where larger.
> 
> Well thanks again, for the prompt answer.
> 
> regards
> Jorgen
> 

No one's mentioned this particular permutation; if you want to use 
'plot' as a logical module in your code, you can just do 'from company 
import plot' =).

-- 
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



More information about the Python-list mailing list