[Zope] Using Python Modules with Zope

complaw@hal-pc.org complaw@hal-pc.org
Wed, 9 Jan 2002 23:41:03 GMT


We just discussed this very subject yesterday on the list.  If you read the
archive from yesterday, you will see that Andreas pointed me to the README file
in /lib/python/Products/PythonScripts/ where you will find instructions on what
to do to make your modules available to python scripts within Zope.

The short version is this:

1.  Create a new directory within /lib/python/Products, e.g., 

mkdir MyModules

so that you now have /lib/python/Products/MyModules.

2.  Copy the file module_access_examples.py into your new subdirectory and call
it __init__.py.  E.g. (from MyModules)

cp ../PythonScripts/module_access_examples.py __init__.py

3.  Using your favorite text editor, edit __init__.py and look for the
allow_module examples.  In my case (for example) I added the file fpformat.py to
the MyModules directory.  Then I edited __init__.py so that it included:

allow_module('fpformat')
ModuleSecurityInfo('fpformat').declarePublic('fpformat', 'fix')

The latter statement allows the python script to use the fix method.

When you are done, restart Zope.

That should do it.

Hope that helps.

Ron

> I new to Zope.  I'm attempting to access Python modules from within Zope.
> These modules are programs we've written, that import stuff like wxWindows
> or our .py modules.  The "Extensions" folder is not the thing to use,
> apparently.  I'm not clear if adding an "External Method" or "Script" is the
> thing to do.  None of the books we have talk clearly about how to do this.
> I need some step-by-step directions with this.  Any suggestions?
> 
> Thanks!
> Mark
>