[Tutor] referencing external functions

Kent Johnson kent37 at tds.net
Fri Nov 14 14:28:57 CET 2008


On Fri, Nov 14, 2008 at 7:56 AM, Robert Berman <bermanrl at embarqmail.com> wrote:
> I have a number of functions written in a python script called script1.py.
> In another  script, script2.py, I need to use a number of the functions
> residing in script1.py. How do I make these functions known to script2.py.

By importing script1. script1.py must be in a directory on PYTHONPATH;
if it is in the same dir as script2.py that will work. Then in
script2.py you can say e.g.

import script1
script1.some_function()

More here or any Python book or tutorial should cover modules and importing:
http://docs.python.org/tutorial/modules.html

Kent


More information about the Tutor mailing list