tags:

views:

39

answers:

2

I have a third-party Python script (foo.py) in a folder that is in my system path (but not the Python sys.path). foo.py is not part of any Python module.

I am writing another script (bar.py) in which I'd like to call a function located in foo.py. Is this possible? Can it be done without explicitly naming the folder of foo.py?

Thanks.

+2  A: 

You can include the path of foo.py in the PYTHONPATH environment variable. The interpreter will look also the directories contained there, so you can make the import just like it was on the same directory.

Khelben
+2  A: 

If Python does not find the module, I don't think there's another way then to specify where it can be found, with one easy way being:

import sys
sys.path.append('/myfolder/itsinthisfolder/')

import foo
ChristopheD