Newbe: Can't import to external script
Ok, I'm new and I know this should be easy. I don't find it documented anywhere, and I've been digging through the list archives without success. I have and external python script in the Extensions directory. I call it, it works. How do a call a method (module) with an absolute path name in the filesystem from this module? I want to import my own module. Running the script from the command line honors #INCDIR to add to the path, of course, but in my zope installation, even placing the module in the Extensions directory won't accomplish the deed. Python can't find it. What am I missing here? Thanks for any help. -- ---------------------------------------------------------------------- * Tom Redfern | Address: 23015 Edmonds Way Apt #A43 Edmonds WA 98020 * * | Phone: 425-778-5320 * ----------------------------------------------------------------------
Tom Redfern wrote:
How do a call a method (module) with an absolute path name in the filesystem from this module?
Give us an example of what you're trying to do...
I want to import my own module. Running the script from the command line honors #INCDIR
what's #INCDIR?!
installation, even placing the module in the Extensions directory won't accomplish the deed.
External Methods aren't _just_ normal .py files, and they don't successfully import other files in the Extensions directory unless you make sure that extensions directory, or any other direcotry you want to import from, is on the python path before Zope is started... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
On 12/7/05, Tom Redfern <zthos@fonebone.net> wrote:
Ok, I'm new and I know this should be easy. I don't find it documented anywhere, and I've been digging through the list archives without success.
I have and external python script in the Extensions directory.
I call it, it works.
How do a call a method (module) with an absolute path name in the filesystem from this module?
I want to import my own module. Running the script from the command line honors #INCDIR to add to the path, of course, but in my zope installation, even placing the module in the Extensions directory won't accomplish the deed. Python can't find it.
zope/Extensions is not part of the sys path. To find out what it is part of it write an externa method like this: import sys def findstuffout(): return '<br>'.join(sys.path)
What am I missing here?
If you want to include your own module, write a script like this: import sys sys.path.append(r'/home/tom/py/mymodule') from mymodule import FatCalculator def calculateFat(n): return FatCalculator.run(n) This assumes that you have a folder called /home/tom/py/mymodule and in it a file called FatCalculator.py with a function in it called run(). For more advanced usage than this I strongly recommend that you write a Python Product.
Thanks for any help.
-- ---------------------------------------------------------------------- * Tom Redfern | Address: 23015 Edmonds Way Apt #A43 Edmonds WA 98020 * * | Phone: 425-778-5320 * ---------------------------------------------------------------------- _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
participants (3)
-
Chris Withers -
Peter Bengtsson -
Tom Redfern