[Zope3-dev] Importing
Chris Withers
chrisw@nipltd.com
Wed, 12 Dec 2001 12:04:51 +0000
Jim Fulton wrote:
>
> > /something/__init__.py
> > /something/somemodule.py
> > /something/abit/__init__.py
> > /something/abit/somemodule2.py
> >
> > ...you'd import the package like:
> >
> > import something
> >
> > BUT, how would you import a method/class in somemodule.py _from_ somemodule2.py?
>
> You have to say something like:
>
> from something.somemodule import someclass
Well, that would be fine, but what is you don't know where the root of your
module path is?
for example, say you write a package that could be used as a Zope product and as
a simple python package.
if you do:
from mypackage.mymodule import someclass
...it won't work in the Zope environment, or anywhere else where mypackage isn't
directly on the python path.
Is that correct?
> Is the point that in 'abit', you don't want to know the name of
> the package(s) that contain it?
Yup
> If so, you can't get there
> from here. There's no way to import from a containing package
> without knowing it's name. This limitation is controversal. :)
Ah :-(
What would be wrong with:
from ..somemodule import somemethod?
or maybe
from abit.parent().somemodule import somemethod
?
cheers,
Chris