Next Chapter | Up | Next Section | Contents

Creating External Methods


To use an External Method, you need to place your Python source code file in the Extensions directory in of your Zope directory (you may need to create this directory), or in an Extensions directory inside a Product directory, e.g. lib/python/Products/MyProduct/Extensions . Next, create an External Method with Zope's management interface. Choose "External Method" from the list of addable objects and click "Add". Then specify your function name and the name of your source file (without suffix). Voila, your Python code runs in Zope without having to master writing a Zope Product from scratch!

External Methods need not actually be bound to the current Folder, they can operate as a function if you wish. Figure 47 provides two examples showing the difference between a function, KnowNothing and a method, FolderTitle .

Example showing the difference between a function and a method

# in Extensions/text.py

 

# this is a normal function

#

def KnowNothing():

"Unbound function"

return "I know nothing of Folders and such."

 

# this is a method of a folder object

#

def FolderTitle(self):

"self is bound to the current folder."

return self.title or id()

 

Next Chapter | Up | Next Section | Contents