Re: [Zope] Python Class Question
From: "Daniel G. Rusch" <drusch@globalcrossing.com> Thanks, I got the first part working.
Now I am trying to get Zope to find my Chicken.py file. I placed my Chicken.py and __init__.py in /lib/python/Shared/DansStuff
I then bounced Zope but it doesn't seem to find my Chicken.py file. I say this because if it found it, Zope would compile it into a Chicken.pyc file wouldn't it??? The __init__.py isn't compiled either!
Does something special need to be in the __init__.py file? ...
If you are using Zope, you must store your classes where they can be accessed by Python. Usually /lib/python/Shared/Local is a good place, make sure to add the __init__.py file inside the folder. You then refer to the class as Shared.Local.Chicken.
-------------------------------------------------- (1) It should work. I have tested it. Nothing special is required for the __init__.py file. (2) Make sure that you have an __init__.py file inside your lib/python/Shared/Local folder. This file can be empty. Or you can provide some __doc__ and __version__ string like Digicool people do. But it really can be an empty file. (3) Inside that folder, create a file Chicken.py, which contains the following three lines: class Chicken: def __init__(self, size): self.size = size (4) This python file will not compile automatically. It will only be compiled when it is imported by some other Zope modules. (5) To test what you want: create an external method. In the folder Extensions inside your Zope root (if you don't have an Extensions folder, you have to create one first), create a file Test.py containing the following lines: import Shared.Local.Chicken def getSize(self): return self.size def test(self): Shared.Local.Chicken.Chicken.getSize = getSize a = Shared.Local.Chicken.Chicken(123) return a.getSize() (6) Go to Zope management screen. Restart Zope. (Or shut it down and restart it manually.) (7) Create an external method with 'Id' = test, 'Function name' = test, Python module file = Test and click on the 'Edit' button, then click on the 'OK' button. If you don't know what an external method is, you've got bigger problems than I thought. :) (8) Hit the 'Try It' tab. Done! now you can use the external method inside your other DTML documents/methods. For instance, you can have a mytest_dtml method with the following lines: <dtml-var standard_html_header> <dtml-var "test()"> <dtml-var standard_html_footer> and it will print the number 123 when you view it. I shouldn't have treated you like a 3-year old. But I guess making instructions as clearly as possible eliminates unnecessary confusions. :) We've all been newbies once. Hung Jung ______________________________________________________ Get Your Private, Free Email at http://www.hotmail.com
participants (1)
-
Hung Jung Lu