15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

12.9. Related Modules<br />

The following are auxiliary modules that you may use when dealing with the import of <strong>Python</strong> modules.<br />

Of these listed below, modulefinder, pkgutil, and zipimport are new as of <strong>Python</strong> 2.3, and the<br />

distutils package was introduced back in version 2.0.<br />

● imp this module gives you access to some lower-level importer functionality.<br />

● modulefinder this is a module that lets you find all the modules that are used by a <strong>Python</strong> script.<br />

You can either use the ModuleFinder class or just run it as a script giving it the filename of a<br />

(nother) <strong>Python</strong> module with which to do module analysis on.<br />

● pkgutil this module gives those putting together <strong>Python</strong> packages for distribution a way to place<br />

package files in various places yet maintain the abstraction of a single "package" file hierarchy. It<br />

uses *.pkg files in a manner similar to the way the site module uses *.pth files to help define the<br />

package path.<br />

● site using this module along with *.pth files gives you the ability to specify the order in which<br />

packages are added to your <strong>Python</strong> path, i.e., sys.path, PYTHONPATH. You do not have to import it<br />

explicitly as the importer already uses it by defaultyou need to use the -S switch when starting<br />

up <strong>Python</strong> to turn it off. Also, you can perform further arbitrary site-specific customizations by<br />

adding a sitecustomize module whose import is attempted after the path manipulations have<br />

been completed.<br />

● zipimport this module allows you to be able to import <strong>Python</strong> modules that are archived in ZIP<br />

files. Note that the functionality in this file is "automagically" called by the importer so there is no<br />

need to import this file for use in any application. We mention it here solely as a reference.<br />

● distutils this package provides support for building, installing, and distributing <strong>Python</strong> modules<br />

and packages. It also aids in building <strong>Python</strong> extensions written in C/C++. More information on<br />

distutils can be found in the <strong>Python</strong> documentation available at these links:<br />

http://docs.python.org/dist/dist.html<br />

http://docs.python.org/inst/inst.html

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!