Website hosting and domain hosting service by

 Back to Index

4 PEP 273: Importing Modules from Zip Archives

The new zipimport module adds support for importing modules from a ZIP-format archive. You don't need to import the module explicitly; it will be automatically imported if a ZIP archive's filename is added to sys.path. For example:


amk@nyman:~/src/python$ unzip -l /tmp/
Archive:  /tmp/
  Length     Date   Time    Name
 --------    ----   ----    ----
     8467  11-26-02 22:30
 --------                   -------
     8467                   1 file
amk@nyman:~/src/python$ ./python
Python 2.3 (#1, Aug 1 2003, 19:54:32) 
>>> import sys
>>> sys.path.insert(0, '/tmp/')  # Add .zip file to front of path
>>> import jwzthreading
>>> jwzthreading.__file__

An entry in sys.path can now be the filename of a ZIP archive. The ZIP archive can contain any kind of files, but only files named *.py, *.pyc, or *.pyo can be imported. If an archive only contains *.py files, Python will not attempt to modify the archive by adding the corresponding *.pyc file, meaning that if a ZIP archive doesn't contain *.pyc files, importing may be rather slow.

A path within the archive can also be specified to only import from a subdirectory; for example, the path /tmp/ would only import from the lib/ subdirectory within the archive.




2002-2004 Website Hosting Service


Disclaimer: This documentation is provided only for the benefits of our hosting customers.
For authoritative source of the documentation, please refer to


Register domain name by Cheap Domain Registrar with free domain hosting services

Cheap domain name - Cheap domain name registration service including free domain hosting services offers domain name registration, domain name transfer and domain search services