How to import a basic class in Script (Python)
To learn zope I am trying to write a basic library page. I wrote a book_py class ... and from search_books_py try to return a list of books to show in a ZPT. now let's suppose all the files (all the py and zpt files) are in the same directory:Library in search_books_py i tried importing the book class in this ways: from book_py import * from Library.book_py import * from here.book_py import * from container.book_py import * they all give ... an unauthorized access to book_py when importing. i even renamed book_py to book.py and tried all the above imports like from book import * ... same error. I've searched Zope Help and it mentions in there that i have to make a new dir in Products called whatever and add to __init__.py the allowimport or something like that, for my package. i tried that too ... same error (haven't restarted zope after... should i?) .
From Zope Help i get that only some standard python modules can be imported this way ...
So is there a way to simply make a class in a Script(Python) and import it in another Script(Python). If there isn't, and i have to make a custom Product for my Book class... please give me a basic example of how can i make that. Thank you for your patience.
--On 18. Juli 2007 12:26:06 +0300 Tudor Gabriel <tdrgabi@gmail.com> wrote:
To learn zope I am trying to write a basic library page. I wrote a book_py class ... and from search_books_py try to return a list of books to show in a ZPT.
now let's suppose all the files (all the py and zpt files) are in the same directory:Library
in search_books_py i tried importing the book class in this ways:
from book_py import * from Library.book_py import * from here.book_py import * from container.book_py import *
Move your code into a "Product" (see Zope Developers Guide) or use an external method. PythonScripts are not equal to an unrestricted Python environment. -aj
On Wed, Jul 18, 2007 at 12:26:06PM +0300, Tudor Gabriel wrote:
I've searched Zope Help and it mentions in there that i have to make a new dir in Products called whatever and add to __init__.py the allowimport or something like that, for my package.
i tried that too ... same error (haven't restarted zope after... should i?) .
Yes. Changes to filesystem code require a restart. -- Paul Winkler http://www.slinkp.com
Tudor Gabriel wrote at 2007-7-18 12:26 +0300:
... now let's suppose all the files (all the py and zpt files) are in the same directory:Library
in search_books_py i tried importing the book class in this ways:
from book_py import * from Library.book_py import * from here.book_py import * from container.book_py import *
The "import *" is not very good style: You do not see where names come from -- this may drastically affect readability of your code A later "import *" may accidentally override names imported in a previous "import". I have seen cases where considerable analysis time was caused by such constructs. If at all, you should have at most a single "import *" -- the first import. Your names look funny. Why do they all end in "_py"? Your Zope folders cannot be reached by the Python interpreter. You cannot import from objects places in Zope's Web hiearachy. -- Dieter
(Wed, Jul 18, 2007 at 12:26:06PM +0300) Tudor Gabriel wrote/schrieb/egrapse:
To learn zope I am trying to write a basic library page. I wrote a book_py class ... and from search_books_py try to return a list of books to show in a ZPT.
now let's suppose all the files (all the py and zpt files) are in the same directory:Library
Please save yourself some time and read http://wiki.zope.org/zope2/ZopeStarter for pointers to valuable information as you start out.
If there isn't, and i have to make a custom Product for my Book class... please give me a basic example of how can i make that.
http://papakiteliatziar.gr/BetaBoring also the stuff linked from the ZopeStarter page. Hope this helps! Regards, Sascha
participants (5)
-
Andreas Jung -
Dieter Maurer -
Paul Winkler -
Sascha Welter -
Tudor Gabriel