diff options
author | Georg Brandl <georg@python.org> | 2008-01-06 16:49:50 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-01-06 16:49:50 (GMT) |
commit | e260ba2d3322b4b97ddd200e1058d80bbba7cb9d (patch) | |
tree | a3b57b09bd793d81bac550ba06ea4014edf98c68 /Doc/library | |
parent | 516787dd98134f1d866b20fb42d8c4da53259b4a (diff) | |
download | cpython-e260ba2d3322b4b97ddd200e1058d80bbba7cb9d.zip cpython-e260ba2d3322b4b97ddd200e1058d80bbba7cb9d.tar.gz cpython-e260ba2d3322b4b97ddd200e1058d80bbba7cb9d.tar.bz2 |
#1325: Add docs and tests for zipimporter.archive and zipimporter.prefix.
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/zipimport.rst | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/Doc/library/zipimport.rst b/Doc/library/zipimport.rst index b6969d7..53eae65 100644 --- a/Doc/library/zipimport.rst +++ b/Doc/library/zipimport.rst @@ -33,21 +33,6 @@ Using the built-in :func:`reload` function will fail if called on a module loaded from a ZIP archive; it is unlikely that :func:`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 :exc:`ImportError`, - so it can be caught as :exc:`ImportError`, too. - - -.. class:: zipimporter - - The class for importing ZIP files. See section :ref:`zipimporter-objects` - for constructor details. - - .. seealso:: `PKZIP Application Note <http://www.pkware.com/business_and_developers/developer/appnote/>`_ @@ -63,18 +48,33 @@ The available attributes of this module are: The PEP to add the import hooks that help this module work. +This module defines an exception: + +.. exception:: ZipImportError + + Exception raised by zipimporter objects. It's a subclass of :exc:`ImportError`, + so it can be caught as :exc:`ImportError`, too. + + .. _zipimporter-objects: zipimporter Objects ------------------- +:class:`zipimporter` is the class for importing ZIP files. .. class:: zipimporter(archivepath) - Create a new zipimporter instance. *archivepath* must be a path to a zipfile. + Create a new zipimporter instance. *archivepath* must be a path to a ZIP file. :exc:`ZipImportError` is raised if *archivepath* doesn't point to a valid ZIP archive. + *archivepath* can also contain a path within the ZIP file -- the importer + object will then look under that path instead of the ZIP file root. For + example, an *archivepath* of :file:`foo/bar.zip/lib` will look for modules + in the :file:`lib` directory inside the ZIP file :file:`foo/bar.zip` + (provided that it exists). + .. method:: zipimporter.find_module(fullname[, path]) @@ -116,11 +116,22 @@ zipimporter Objects :exc:`ZipImportError` if it wasn't found. -Examples --------- +.. attribute:: zipimporter.archive + + The file name of the importer's associated ZIP file. + + +.. attribute:: zipimporter.prefix + + The path within the ZIP file where modules are searched; see + :class:`zipimporter` for details. + .. _zipimport-examples: +Examples +-------- + Here is an example that imports a module from a ZIP archive - note that the :mod:`zipimport` module is not explicitly used. :: |