[Zope] Newbe: Can't import to external script

Peter Bengtsson peter at fry-it.com
Wed Dec 7 05:10:22 EST 2005


On 12/7/05, Tom Redfern <zthos at 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 at 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


More information about the Zope mailing list