Problem with packages and modules

Jørgen Hansen jorgenhansen at hotmail.com
Tue Apr 9 09:42:11 EDT 2002


Hello,

I have been working for some time now with Python and really enjoy it.
Right now I am having serious difficulties crasping several issues
when using packages.


This is an example of directory hierachy:

company/                   Top-level package
    __init__.py            Initialize the company package
    plot/                  A plot package
        __init__.py
        axes.py            Modules in the plot package
        axis.py
        bar.py
        figure.py
        line.py
        plotobject.py
        points.py
        tick.py
        utils.py    
    log.py                 Modules in the company package
    utils.py


If I were to use the plot package I would type in
   >>> from company import plot

and assume that I could access modules as:
   >>> plot.figure.Figure()    # where Figure is a class name.

but this is not the case. Neither of the modules in the plot package
are available, and it doesn't matter if I use the __all__ attribute in
__init__.py and type in all the module names.

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.

Can someone please help me. I don't now what missing out on. I've read
the documentation, Googled quite a lot, but haven't found any answers.

Regards
Jorgen



More information about the Python-list mailing list