[Zope] Calling a File from an External Method

Passin, Tom tpassin@mitretek.org
Mon, 13 Jan 2003 16:11:30 -0500


[ beno]
> I'm calling a function with a file name from an external=20
> method. I need to=20
> pass a variable to the method, so I have a line like this:
>=20
> <dtml-var expr=3D"externalMethod('file')">
>=20
> but the error comes back thus:
>=20
> IOError: [Errno 2] No such file or directory: 'file'
> when said file does indeed exist in the same directory as the=20
> DTML Method=20
> and also the External Method.

No, the DTML method exists on the ZODB, not in the file system.
Depending on your terminology, the External Method also lives in the
ZODB, and it points to a file in the file system that contains the
actual Python code for the method.

The external method's code is found (by Zope) because Zope knows where
it is on the Python path.  The external code is trying to open the file
based on the **file system's** current directory, not the Python path.
So your method cannot find the file.

Use file paths relative to the code of the external method which you can
work out by having the code find its own location.  The best way to do
that is to remove all the code from the external method folder and put
it into a module on the Python path.  The external method would then
have a one-line function that calls the code you have just relocated. =20

That code can find its own location in the file system.

Cheers,

Tom P