[ beno]
I'm calling a function with a file name from an external method. I need to pass a variable to the method, so I have a line like this:
<dtml-var expr="externalMethod('file')">
but the error comes back thus:
IOError: [Errno 2] No such file or directory: 'file' when said file does indeed exist in the same directory as the DTML Method 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. That code can find its own location in the file system. Cheers, Tom P