Skip to Content
Python: Essential Reference, Third Edition
book

Python: Essential Reference, Third Edition

by David Beazley
February 2006
Intermediate to advanced content levelIntermediate to advanced
648 pages
14h 53m
English
Sams
Content preview from Python: Essential Reference, Third Edition

The Module Search Path

When loading modules, the interpreter searches the list of directories in sys.path. The following is a typical value of sys.path:

['',  '/usr/local/lib/python2.0',
      '/usr/local/lib/python2.0/plat-sunos5',
      '/usr/local/lib/python2.0/lib-tk',
      '/usr/local/lib/python2.0/lib-dynload',
      '/usr/local/lib/python2.0/site-packages']

The empty string '’ refers to the current directory.

To add new directories to the search path, simply append them to this list.

In addition to directories, ZIP archive files containing Python modules can be added to the search path. This can be a convenient way to package a collection of modules as a single file. For example, suppose you created two modules, foo.py and bar.py, and placed them in a zip file ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python: Essential Reference

Python: Essential Reference

David M. Beazley

Publisher Resources

ISBN: 0672328623Purchase book