[Zope] Another import doesn't find the module

Stacy Roberts Ladnier Stacy.Roberts@noaa.gov
Wed, 28 May 2003 14:33:21 -0500


> > My Structure has the following
> >    -FGDC (directory)
> >        - __init__.py
> >        - profile.py
> >        - DISTRIB.py
       -scripts (directory)
           - script1.py
       -extensions (directory
           -DISTINFO.py
> > 
> > The line I had that read 
> >    from Products.Resources.FGDC import profile 
> > failed. 

Before class1 of DISTINFO.py, I tried the above statement and recieve 
a 'can't import name profile'. 

> > However, this line works like a charm:
> >    from Products.Resources.FGDC import DISTRIB

and is located directly under the above line. Totally baffling me.

There is no syntax error in profile.py as I am using it from other 
methods and the object is added without trouble or error.

To maybe clarify a few things, this is the basics of what I am 
attempting to accomplish. 
      I have an object (distinfo) that is created inside of another 
record. This operation works fine. Now, when a special condition 
exists, the user may create an object also to be named distinfo, yet 
this one will have one more feature. I DO NOT want to do a monkey patch 
here. I want the user to specifically choose when the alternate object 
is to be added.
      Distinfo #1 is in the FGDC directory. Distinfo #2 will live in 
the extensions directory. I want to set of a script in the scripts 
directory that will cause the #2 to be added. By the way, both of these 
objects(#1 and #2) should have the same metatype.




----- Original Message -----
From: "Passin, Tom" <tpassin@mitretek.org>
Date: Wednesday, May 28, 2003 1:30 pm
Subject: RE: [Zope] Another import doesn't find the module

> [Stacy Roberts Ladnier]
> 
> > My Structure has the following
> >    -FGDC (directory)
> >        - __init__.py
> >        - profile.py
> >        - DISTRIB.py
> > 
> > The line I had that read 
> >    from Products.Resources.FGDC import profile 
> > failed as you said it should. 
> > 
> > However, this line works like a charm:
> >    from Products.Resources.FGDC import DISTRIB
> > 
> > BTW, I always interpreted this to mean
> >     from <directory> import <module>
> > 
> > Can you explain the *why's* on this one?? 
> 
> 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=os.path.dirname(__file__)
> 
> Then you can import BASEPATH from the package.
> 
> Cheers,
> 
> Tom P
>