IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
29.2 zipimport -- Import modules from Zip archives

29.2 zipimport -- Import modules from Zip archives

New in version 2.3.

This module adds the ability to import Python modules (*.py, *.py[co]) and packages from ZIP-format archives. It is usually not needed to use the zipimport module explicitly; it is automatically used by the builtin import mechanism for sys.path items that are paths to ZIP archives.

Typically, sys.path is a list of directory names as strings. This module also allows an item of sys.path to be a string naming a ZIP file archive. The ZIP archive can contain a subdirectory structure to support package imports, and a path within the archive can be specified to only import from a subdirectory. For example, the path /tmp/example.zip/lib/ would only import from the lib/ subdirectory within the archive.

Any files may be present in the ZIP archive, but only files .py and .py[co] are available for import. ZIP import of dynamic modules (.pyd, .so) is disallowed. Note that if an archive only contains .py files, Python will not attempt to modify the archive by adding the corresponding .pyc or .pyo file, meaning that if a ZIP archive doesn't contain .pyc files, importing may be rather slow.

Using the built-in reload() function will fail if called on a module loaded from a ZIP archive; it is unlikely that reload() would be needed, since this would imply that the ZIP has been altered during runtime.

The available attributes of this module are:

exception ZipImportError
Exception raised by zipimporter objects. It's a subclass of ImportError, so it can be caught as ImportError, too.

class zipimporter
The class for importing ZIP files. See ``zipimporter Objects'' (section 29.2.1) for constructor details.

See Also:

PKZIP Application Note
Documentation on the ZIP file format by Phil Katz, the creator of the format and algorithms used.

PEP 0273, Import Modules from Zip Archives
Written by James C. Ahlstrom, who also provided an implementation. Python 2.3 follows the specification in PEP 273, but uses an implementation written by Just van Rossum that uses the import hooks described in PEP 302.

PEP 0302, New Import Hooks
The PEP to add the import hooks that help this module work.



See About this document... for information on suggesting changes.