plsulliv...@gmail.com wrote:
I have several functions which I would like to store in a different
directory so several programs can use them. I can't seem to find much
information about how to call a function if the function code is not
actually in the script itself.
The problem: do I have to cut and paste functions into a script or can
I store them in a directory and call them from a script in another
directory. If the latter is possible, how is this done? Thanks.

Yes of course. It is called module.

file: functioncoll.py

def foo(): pass
def bar(): pass

file program.py
import functioncoll

functioncoll.foo()


Note: functioncoll.py must be in your python search path. One way to easily ensure it is in the search path is to put functioncoll.py in the same directory as program.py

Note that all the usual tricks with import also works, like
from functioncoll import foo, bar
import functioncoll as fc
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to