summaryrefslogtreecommitdiffstats
path: root/Doc/library/zipimport.rst
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-01-06 17:05:40 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-01-06 17:05:40 (GMT)
commit7f044315f49836fbe472b53e089e733439ca5ece (patch)
tree411215f12c3970bfd47372959fe711887da690bc /Doc/library/zipimport.rst
parentfaf2f63faf9e73c816f0a8bf7f5998757280b50a (diff)
downloadcpython-7f044315f49836fbe472b53e089e733439ca5ece.zip
cpython-7f044315f49836fbe472b53e089e733439ca5ece.tar.gz
cpython-7f044315f49836fbe472b53e089e733439ca5ece.tar.bz2
Merged revisions 59774-59783 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59774 | georg.brandl | 2008-01-06 16:41:50 +0100 (Sun, 06 Jan 2008) | 2 lines #1501: document that 0**0 == 1. ........ r59775 | georg.brandl | 2008-01-06 16:48:20 +0100 (Sun, 06 Jan 2008) | 2 lines #759525: document that dir() doesn't return metaclass attrs when given a class as arg. ........ r59776 | georg.brandl | 2008-01-06 16:55:26 +0100 (Sun, 06 Jan 2008) | 2 lines #1615275: clarify return object types of different tempfile factories. ........ r59777 | georg.brandl | 2008-01-06 17:01:26 +0100 (Sun, 06 Jan 2008) | 2 lines #1727024: document that Popen.returncode is set by Popen.poll/wait. ........ r59778 | georg.brandl | 2008-01-06 17:04:56 +0100 (Sun, 06 Jan 2008) | 2 lines #1686390: add example for csv.Sniffer use. ........ r59779 | georg.brandl | 2008-01-06 17:12:39 +0100 (Sun, 06 Jan 2008) | 2 lines #1559684: document that shutil.copy* doesn't copy all metadata on Posix and Windows too. ........ r59780 | georg.brandl | 2008-01-06 17:17:56 +0100 (Sun, 06 Jan 2008) | 2 lines #1582: document __reversed__, patch by Mark Russell. ........ r59781 | georg.brandl | 2008-01-06 17:22:56 +0100 (Sun, 06 Jan 2008) | 2 lines #1499: Document compile() exceptions. ........ r59782 | georg.brandl | 2008-01-06 17:49:50 +0100 (Sun, 06 Jan 2008) | 2 lines #1325: Add docs and tests for zipimporter.archive and zipimporter.prefix. ........
Diffstat (limited to 'Doc/library/zipimport.rst')
-rw-r--r--Doc/library/zipimport.rst47
1 files changed, 29 insertions, 18 deletions
diff --git a/Doc/library/zipimport.rst b/Doc/library/zipimport.rst
index 6845bf7..ed9c631 100644
--- a/Doc/library/zipimport.rst
+++ b/Doc/library/zipimport.rst
@@ -27,21 +27,6 @@ Any files may be present in the ZIP archive, but only files :file:`.py` and
corresponding :file:`.pyc` or :file:`.pyo` file, meaning that if a ZIP archive
doesn't contain :file:`.pyc` files, importing may be rather slow.
-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/>`_
@@ -57,18 +42,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])
@@ -110,11 +110,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. ::