[Zope3-dev] Importing
Chris Withers
chrisw@nipltd.com
Tue, 11 Dec 2001 17:48:53 +0000
Jim Fulton wrote:
>
> > +1. Suitably obscure and clear at the same time.
>
> Do you think that the name abreviation is useful?
Hmmm... Guido and Jim in one thread vaguely to do with importing, I might as
well toss this in...
If you have a file structure like:
/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?
I found the zope notion of a global name 'Products' very useful for this, and I
could only do the same in a non-Zope environment doing the evillest of hacks,
along the lines of:
something_package = string.join(string.split(__name__,'.')[:-2],'.')
exec "import %s.abit" % something_package
Now, how should I be doing this? (and in Zope 3?)
cheers,
Chris