Next: An Example
Up: Writing Modules
Previous: Writing Modules
  Contents
In Python, a module is simply a file which contains Python code and which can
be imported into some other program. Thus, if you have a collection of functions
which you'd like to use in other python programs, you can simply put them all in
one file, say myfunctions.py, and use the import statement to
make those functions available to you. If your module is located in your working
directory, Python will always find it. Otherwise, it must be located in Python's
search path. You can view the search path with the following Python statements:
import sys
sys.path
Since sys.path is just a list, you can append the names of other
directories to search onto this list before using an import statement, to
allow you to access modules which are not on the search path. But if you keep your
modules in one location, a more useful approach may be to set the PYTHONPATH
environmental variable to that location in the appropriate startup file for your
operating system. That way, all the Python programs you run will be able to use
your modules.
Next: An Example
Up: Writing Modules
Previous: Writing Modules
  Contents
Phil Spector
2003-11-12