Problem with packages and modules

Jørgen Hansen jorgenhansen at hotmail.com
Wed Apr 10 05:41:57 EDT 2002


Philip Swartzleonard <starx at pacbell.net> wrote in message news:<Xns91EBEF972B8BFRASXnewsDFE1 at 130.133.1.4>...
> 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' =).

But that would still require that I import the required modules of
'plot' in the __init__.py file of the 'plot' package. At least that is
my experience, correct me if I'm wrong.

/Jorgen



More information about the Python-list mailing list