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 .

Extension directory

 

Next, create an External Method with Zope's management interface. Choose "External Method" from the list of addable objects. 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! Stan creates the text.py file under the Extensions directory, just copy and paste from the example the function

Add External Method

 

External Methods need not actually be bound to the current Folder, but can operate as a function if you wish. Figure 57 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()

 

When adding external methods, you will have to option of trying out your code before implementing the code. The "Try It" tag, allows you to experiment with your python program. Of course the powerful, "Undo" option can wipe away your mistakes with a single key stroke.

External Methods Try It

 

Next Chapter | Up | Next Section | Contents

SUBSECTIONS


Banner.Novgorod.Ru