Newbie need help

Fredrik Lundh fredrik at pythonware.com
Wed Oct 20 06:13:02 EDT 1999


Marco Guidi <ENONMELOSPAMMATEguidi at sssup.it> wrote:
> I've a very silly problem, but I'm not able to solve it.

silly or not, Zope questions are probably better
asked on the appropriate zope mailing list:

http://www.zope.org/Resources/MailingLists

...but alright, I can make an unqualified guess:

> >>> import DocumentTemplate
> >>> import Common
...
> Why did I get the error
> 
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> ImportError: No module named Common ?

probably because the App directory isn't
on your Python path.
 
> and Why could I import DocumentTemplate correctly ?

probably because it's a package (if there's a
file called __init__.py in that directory, it's
a package)
 
> Which is the correct way for importing a file residing in
> some directory different from the one from wich I run python
> (and different from Extensions or other predefined directories) ?

first, make sure the right things are on your
Python path (the PYTHONPATH variable.  to
see the current setting, import sys and print
the value of sys.path).  the Zope installation
guidelines should tell you what (if anything)
you need to have on the path.

package directories shouldn't be on the path,
though.  to import things from a package, use:

    from App import Common

or

    import App.Common

importing App or DocumentTemplate imports
the package itself, which may or may not be
a relevant thing to do, depending on what the
package designer intended...

hope this helps!

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list