Describing the Module Search Path
- When loading modules, the interpreter searches the list of directories in
sys.path - The first entry in
sys.pathis typically an emptry string'' - This refers to the current working directory
-
Other entries in
sys.pathmay consist of:- Directory names
- Zip files
- Archive files
- etc.
- Suppose we created two modules
foo.pyandbar.py - Then, we placed them in a zip file called
modules.zip - The file could be added to the Python search path:
>>> import sys
>>> sys.path.append('modules.zip')
>>> import foo, barReferences
Previous
Next