Next Chapter | Up | Next Section | Contents

Importing Modules and Packages


External Methods may access Zope packages and modules, and/or other Python packages. So if you have a cool Python package you want to use with Zope, the easiest thing to do is to write an External Method. For example:

import MyCoolPackage

 

def MyObject(self):

"use a cool object"

myObject=MyCoolPackage.MyCoolClass()

return myObject.myMethod()

This example uses a MyObject instance whose class is defined in MyCoolPackage . You may need to manipulate the Python Path to get access to your Python packages.

Zope provides a convenient solution for packaging classes that you wish to use in External Methods. This solution is the Shared package, located in lib/python/Shared . To use this Shared package, create a sub-package inside Shared package with the name of your organization (or personal name). Then create further sub-packages if you wish. For example, instead of manipulating the Python path to allow you to import your MyCoolPackage, you could simply relocate that package to the Shared package, lib/python/Shared/MyName/MyCoolPackge, where MyName is your organization or personal name. Now Zope has access to your package.

Next Chapter | Up | Next Section | Contents

Banner.Novgorod.Ru