[Zope] (no subject)
Hung Jung Lu
hungjunglu@hotmail.com
Thu, 09 Mar 2000 09:54:28 PST
"daniel g. rusch" <drusc-@globalcrossing.com> wrote:
original article:http://www.egroups.com/group/zope/?start=25548
>Let's say I have a class called Chicken in a file called Chicken.py
>
>Now let's say I want to add a method called getSize() to the Chicken
>class. It's a piece of cake to add the method in the Chicken.py file.
>
>But, is it possible to add the method to the Chicken class, but have
>that method in a different file, i.e. some file other than Chicken.py?
Is this a pure Python question? (Zope External methods
are VERY different from Python methods, that's why I need
to ask.)
If you are talking about pure Python, sure, you can add
class members (data or method) at any time.
-----------------------------
File A.py:
class Chicken:
def __init__(self, size):
self.size = size
--------------------------------
File B.py:
import A
def getSize(self):
return self.size
A.Chicken.getSize = getSize
b = A.Chicken(123)
print b.getSize() # prints 123
--------------------------------
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.
Hung Jung
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com