[Zope] Another import doesn't find the module
Passin, Tom
tpassin@mitretek.org
Wed, 28 May 2003 14:30:15 -0400
[Stacy Roberts Ladnier]
> My Structure has the following
> -FGDC (directory)
> - __init__.py
> - profile.py
> - DISTRIB.py
>=20
> The line I had that read=20
> from Products.Resources.FGDC import profile=20
> failed as you said it should.=20
>=20
> However, this line works like a charm:
> from Products.Resources.FGDC import DISTRIB
>=20
> BTW, I always interpreted this to mean
> from <directory> import <module>
>=20
> Can you explain the *why's* on this one??=20
An import that fails when the import statement looks perfectly fine is
often an indication that there is an error in the module to be imported.
It could be a simple indentation error, or something more serious. What
is the error message?
Import statements import packages, not directories. The __init__.py
statement is processed when you import the package, and the modules are
processed when you import them from the package. Although most
__init__.py files are empty, some code does some really serious work in
them I like to use them to store the absolute directory path, which I
can use withr elative paths to compute where to put or find files - like
this (in the __init__.py ) -
import os.path
BASEPATH=3Dos.path.dirname(__file__)
Then you can import BASEPATH from the package.
Cheers,
Tom P