Problem with packages and modules
Max M
maxm at mxm.dk
Tue Apr 9 10:26:28 EDT 2002
Jørgen Hansen wrote:
> 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.
You will need to add the full path to a module.
from company.plot.figure import Figure
fig = Figure()
or
import company.plot.figure
fig = company.plot.figure.Figure()
or
from company.plot import figure
fig = figure.Figure()
> 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.
regards Max M
More information about the Python-list
mailing list