[Zope] open

Passin, Tom tpassin at mitretek.org
Thu Jun 3 15:44:47 EDT 2004


> From: zope-bounces at zope.org [mailto:zope-bounces at zope.org] On 
> Behalf Of Abraham Arellano Tavara

> sorry but which files properties are thoses.... and my
> original file is in 
> the directory "Extensions" outside the Zope directory 
> structure, there i use 
> the open but i don't know how. Thanks for the help, Abraham.
> 

Your External Method file is in the Extensions folder, which is normally
part of your Zope installation's directory tree.

Here is an example that I have used successfully.

In some other directory, put a file containing the python code that you
wish to execute.  For example -

Zope
   Extensions
   ...(other Zope directories)

YourProject
   __init__.py
   YourPythonFile.py
   Data

The __init__.py file turns that directory into a Python "package".
"Data" is a subdirectory.  In the __init__.py file, put code similar to
the following -

import os.path

BASEPATH=os.path.dirname(__file__)
DATA_PATH=os.path.join(BASEPATH,'Data')

Now put YourProject into the Python path.  There are several ways to do
this, but the easiest is to write the absolute path to the directory on
one line in a .pth file - say "project.pth".  Put this file into the
same directory as  Zope's Python executable.

In your external method, place code similar to the following -

from YourProject import BASEPATH, DATA_PATH
from YourProject import YourPythonFile.YourFunction

Now the paths and functions are available to the whatever external
method code you wish to write.  I recommend just computing the right
directories and calling the module's code, something like this -

Import os.path
def external_method(filename):
   yourPythonFile.yourFunction(os.path.join(DATA_PATH,'data.txt'))

Of course, you can pass the REQUEST or whatever else you like as well.

Cheers,

Tom P



More information about the Zope mailing list