"import" within external method file doesn't work
Hello all, I've tried to write a simple external method as described a thousand times in the excellent documentation. Within the file "A", I'd like to import another file "B" within the same directory. But when I try to add a function from "A" as an external method somewhere in the tree and try to view the DTML document from which the method is called, Zope tells me that it can't find the module I tried to import in "A". Is this a bug or I'm too much newbie? Any help appreciated alot Christian
From: christian@newopenness.de Date sent: Tue, 28 Dec 1999 01:04:53 +0100 To: zope@zope.org Subject: [Zope] "import" within external method file doesn't work
Hello all,
I've tried to write a simple external method as described a thousand times in the excellent documentation. Within the file "A", I'd like to import another file "B" within the same directory. But when I try to add a function from "A" as an external method somewhere in the tree and try to view the DTML document from which the method is called, Zope tells me that it can't find the module I tried to import in "A". Is this a bug or I'm too much newbie?
too much newbie ;-) The point is that the python modules in the Extensions directory are not really modules _and_ they cannot import from the Extensions directory itself. You should put your module_to_be_imported somewhere in a directory in the pythonpath. <zopehome>/lib/python/Shared/<yourstuff> is a good place. Don't forget to add a (presumable empty) __init__.py module in the <yourstuff> directory. The module may then be imported by the python statement import Shared.<yourstuff>.yourmodule or from Shared.yourstuff import yourmodule. See the standard python documentation on http://www.python.org for more information on all this. Rik
Rik Hoekstra wrote:
too much newbie ;-) The point is that the python modules in the Extensions directory are not really modules _and_ they cannot import from the Extensions directory itself. You should put your module_to_be_imported somewhere in a directory in the pythonpath. <zopehome>/lib/python/Shared/<yourstuff> is a good place. Don't forget to add a (presumable empty) __init__.py module in the <yourstuff> directory. The module may then be imported by the python statement import Shared.<yourstuff>.yourmodule or from Shared.yourstuff import yourmodule.
Okay, thans, it works now :-) Christian -- \|/ ____ \|/ http://www.bnv-bamberg.de/home/sledge/ "@'/ ,. \'@" http://www.newopenness.de/lug-bamberg/ (LUG Bamberg) /_| \__/ |_\ \__U_/ http://fsub.schule.de/ (Freie Software und Bildung)
christian@newopenness.de wrote:
method somewhere in the tree and try to view the DTML document from which the method is called, Zope tells me that it can't find the module I tried to import in "A". Is this a bug or I'm too much newbie?
I've encountered this also and it goes away if I restart the Zope process. The other thing that has gotten me is "shadowing" by Zope classes, e.g. defining a User class of your own will get shadowed by Zope's User class if you happen to put the class in the Extensions directory. This is easy enough to fix with something like: import MyVeryOwnClasses.User ------------------------------------------------------ Andres Corrada-Emmanuel Email: andres@corrada.com Owner http://www.corrada.com/mamey Mamey Phone: (413) 587-9595 ------------------------------------------------------
participants (4)
-
Andres Corrada -
Christian Selig -
christian@newopenness.de -
Rik Hoekstra