2007-08-15 11:28:22 -03:00
|
|
|
:mod:`zipimport` --- Import modules from Zip archives
|
|
|
|
=====================================================
|
|
|
|
|
|
|
|
.. module:: zipimport
|
2019-11-25 18:17:59 -04:00
|
|
|
:synopsis: Support for importing Python modules from ZIP archives.
|
2016-06-11 16:02:54 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. moduleauthor:: Just van Rossum <just@letterror.com>
|
|
|
|
|
2019-05-15 13:18:35 -03:00
|
|
|
**Source code:** :source:`Lib/zipimport.py`
|
|
|
|
|
2016-06-11 16:02:54 -03:00
|
|
|
--------------
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
This module adds the ability to import Python modules (:file:`\*.py`,
|
2017-03-11 01:02:52 -04:00
|
|
|
:file:`\*.pyc`) and packages from ZIP-format archives. It is usually not
|
2007-08-15 11:28:22 -03:00
|
|
|
needed to use the :mod:`zipimport` module explicitly; it is automatically used
|
2011-06-25 13:40:06 -03:00
|
|
|
by the built-in :keyword:`import` mechanism for :data:`sys.path` items that are paths
|
2007-08-15 11:28:22 -03:00
|
|
|
to ZIP archives.
|
|
|
|
|
2011-06-25 13:40:06 -03:00
|
|
|
Typically, :data:`sys.path` is a list of directory names as strings. This module
|
|
|
|
also allows an item of :data:`sys.path` to be a string naming a ZIP file archive.
|
2007-08-15 11:28:22 -03:00
|
|
|
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
|
2013-02-23 14:26:56 -04:00
|
|
|
subdirectory. For example, the path :file:`example.zip/lib/` would only
|
2007-08-15 11:28:22 -03:00
|
|
|
import from the :file:`lib/` subdirectory within the archive.
|
|
|
|
|
2021-12-16 05:12:24 -04:00
|
|
|
Any files may be present in the ZIP archive, but importers are only invoked for
|
|
|
|
:file:`.py` and :file:`.pyc` files. ZIP import of dynamic modules
|
2007-08-15 11:28:22 -03:00
|
|
|
(:file:`.pyd`, :file:`.so`) is disallowed. Note that if an archive only contains
|
|
|
|
:file:`.py` files, Python will not attempt to modify the archive by adding the
|
2015-04-13 15:21:02 -03:00
|
|
|
corresponding :file:`.pyc` file, meaning that if a ZIP archive
|
2007-08-15 11:28:22 -03:00
|
|
|
doesn't contain :file:`.pyc` files, importing may be rather slow.
|
|
|
|
|
2024-03-28 03:54:51 -03:00
|
|
|
.. versionchanged:: 3.13
|
|
|
|
ZIP64 is supported
|
|
|
|
|
2018-09-25 16:15:47 -03:00
|
|
|
.. versionchanged:: 3.8
|
|
|
|
Previously, ZIP archives with an archive comment were not supported.
|
Merged revisions 77185-77188,77262,77313,77317,77331-77333,77337-77338 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77185 | andrew.kuchling | 2009-12-31 10:17:05 -0600 (Thu, 31 Dec 2009) | 1 line
Add some items
........
r77186 | benjamin.peterson | 2009-12-31 10:28:24 -0600 (Thu, 31 Dec 2009) | 1 line
update expat comment
........
r77187 | andrew.kuchling | 2009-12-31 10:38:53 -0600 (Thu, 31 Dec 2009) | 1 line
Add various items
........
r77188 | benjamin.peterson | 2009-12-31 10:49:37 -0600 (Thu, 31 Dec 2009) | 1 line
add another advancement
........
r77262 | andrew.kuchling | 2010-01-02 19:15:21 -0600 (Sat, 02 Jan 2010) | 1 line
Add a few items
........
r77313 | benjamin.peterson | 2010-01-04 18:04:19 -0600 (Mon, 04 Jan 2010) | 1 line
add a test about hashing array.array
........
r77317 | georg.brandl | 2010-01-05 12:14:52 -0600 (Tue, 05 Jan 2010) | 1 line
Add Stefan.
........
r77331 | georg.brandl | 2010-01-06 11:43:06 -0600 (Wed, 06 Jan 2010) | 1 line
Small fixes to test_cmd: fix signature of do_shell, remove duplicate import, add option to run the custom Cmd class.
........
r77332 | georg.brandl | 2010-01-06 12:02:16 -0600 (Wed, 06 Jan 2010) | 7 lines
#5991: let completion for the "help" command include help topics.
This also simplifies the Cmd.get_names() method implementation; it was written
at a time where dir() didn't consider base class attributes.
........
r77333 | georg.brandl | 2010-01-06 12:26:08 -0600 (Wed, 06 Jan 2010) | 1 line
#5950: document that zip files with comments are unsupported in zipimport.
........
r77337 | r.david.murray | 2010-01-06 21:09:08 -0600 (Wed, 06 Jan 2010) | 3 lines
Add -W to the 'basics', 'opt', and 'all' test runs so that we get verbose
information if a failure happens.
........
r77338 | r.david.murray | 2010-01-06 22:04:28 -0600 (Wed, 06 Jan 2010) | 2 lines
Fix inadvertent checkin of debug line.
........
2010-01-09 14:53:06 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. seealso::
|
|
|
|
|
2016-02-26 14:37:12 -04:00
|
|
|
`PKZIP Application Note <https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT>`_
|
2007-08-15 11:28:22 -03:00
|
|
|
Documentation on the ZIP file format by Phil Katz, the creator of the format and
|
|
|
|
algorithms used.
|
|
|
|
|
2010-05-14 11:36:18 -03:00
|
|
|
:pep:`273` - Import Modules from Zip Archives
|
2007-08-15 11:28:22 -03:00
|
|
|
Written by James C. Ahlstrom, who also provided an implementation. Python 2.3
|
2018-10-26 19:58:26 -03:00
|
|
|
follows the specification in :pep:`273`, but uses an implementation written by Just
|
|
|
|
van Rossum that uses the import hooks described in :pep:`302`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2020-11-13 19:14:58 -04:00
|
|
|
:mod:`importlib` - The implementation of the import machinery
|
|
|
|
Package providing the relevant protocols for all importers to
|
|
|
|
implement.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
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.
........
2008-01-06 13:05:40 -04:00
|
|
|
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.
|
|
|
|
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. _zipimporter-objects:
|
|
|
|
|
|
|
|
zipimporter Objects
|
|
|
|
-------------------
|
|
|
|
|
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.
........
2008-01-06 13:05:40 -04:00
|
|
|
:class:`zipimporter` is the class for importing ZIP files.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. class:: zipimporter(archivepath)
|
|
|
|
|
Merged revisions 63066-63076,63079,63081-63085,63087-63097,63099,63101-63104 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63066 | georg.brandl | 2008-05-11 10:56:04 -0400 (Sun, 11 May 2008) | 2 lines
#2709 followup: better description of Tk's pros and cons.
........
r63067 | georg.brandl | 2008-05-11 11:05:13 -0400 (Sun, 11 May 2008) | 2 lines
#1326: document and test zipimporter.archive and zipimporter.prefix.
........
r63068 | georg.brandl | 2008-05-11 11:07:39 -0400 (Sun, 11 May 2008) | 2 lines
#2816: clarify error messages for EOF while scanning strings.
........
r63069 | georg.brandl | 2008-05-11 11:17:41 -0400 (Sun, 11 May 2008) | 3 lines
#2787: Flush stdout after writing test name, helpful when running
hanging or long-running tests. Patch by Adam Olsen.
........
r63070 | georg.brandl | 2008-05-11 11:20:16 -0400 (Sun, 11 May 2008) | 3 lines
#2803: fix wrong invocation of heappush in seldom-reached code.
Thanks to Matt Harden.
........
r63073 | benjamin.peterson | 2008-05-11 12:38:07 -0400 (Sun, 11 May 2008) | 2 lines
broaden .bzrignore
........
r63076 | andrew.kuchling | 2008-05-11 15:15:52 -0400 (Sun, 11 May 2008) | 1 line
Add message to test assertion
........
r63083 | andrew.kuchling | 2008-05-11 16:08:33 -0400 (Sun, 11 May 2008) | 1 line
Try setting HOME env.var to fix test on Win32
........
r63092 | georg.brandl | 2008-05-11 16:53:55 -0400 (Sun, 11 May 2008) | 2 lines
#2809 followup: even better split docstring.
........
r63094 | georg.brandl | 2008-05-11 17:03:42 -0400 (Sun, 11 May 2008) | 4 lines
- #2250: Exceptions raised during evaluation of names in rlcompleter's
``Completer.complete()`` method are now caught and ignored.
........
r63095 | georg.brandl | 2008-05-11 17:16:37 -0400 (Sun, 11 May 2008) | 2 lines
Clarify os.strerror()s exception behavior.
........
r63097 | georg.brandl | 2008-05-11 17:34:10 -0400 (Sun, 11 May 2008) | 2 lines
#2535: remove duplicated method.
........
r63104 | alexandre.vassalotti | 2008-05-11 19:04:27 -0400 (Sun, 11 May 2008) | 2 lines
Moved the Queue module stub in lib-old.
........
2008-05-15 21:41:41 -03:00
|
|
|
Create a new zipimporter instance. *archivepath* must be a path to a ZIP
|
|
|
|
file, or to a specific path within a ZIP file. 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).
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
:exc:`ZipImportError` is raised if *archivepath* doesn't point to a valid ZIP
|
|
|
|
archive.
|
|
|
|
|
2023-05-03 08:55:22 -03:00
|
|
|
.. versionchanged:: 3.12
|
|
|
|
|
|
|
|
Methods ``find_loader()`` and ``find_module()``, deprecated in 3.10 are
|
|
|
|
now removed. Use :meth:`find_spec` instead.
|
|
|
|
|
2020-11-13 19:14:58 -04:00
|
|
|
.. method:: create_module(spec)
|
|
|
|
|
|
|
|
Implementation of :meth:`importlib.abc.Loader.create_module` that returns
|
|
|
|
:const:`None` to explicitly request the default semantics.
|
|
|
|
|
|
|
|
.. versionadded:: 3.10
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: exec_module(module)
|
|
|
|
|
|
|
|
Implementation of :meth:`importlib.abc.Loader.exec_module`.
|
|
|
|
|
|
|
|
.. versionadded:: 3.10
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: find_spec(fullname, target=None)
|
|
|
|
|
|
|
|
An implementation of :meth:`importlib.abc.PathEntryFinder.find_spec`.
|
|
|
|
|
|
|
|
.. versionadded:: 3.10
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: get_code(fullname)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return the code object for the specified module. Raise
|
2020-12-18 20:09:54 -04:00
|
|
|
:exc:`ZipImportError` if the module couldn't be imported.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: get_data(pathname)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-10-12 15:10:51 -03:00
|
|
|
Return the data associated with *pathname*. Raise :exc:`OSError` if the
|
2008-04-24 22:59:09 -03:00
|
|
|
file wasn't found.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-10-12 15:10:51 -03:00
|
|
|
.. versionchanged:: 3.3
|
2023-10-09 06:18:06 -03:00
|
|
|
:exc:`IOError` used to be raised, it is now an alias of :exc:`OSError`.
|
2011-10-12 15:10:51 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-02-07 23:37:27 -04:00
|
|
|
.. method:: get_filename(fullname)
|
|
|
|
|
|
|
|
Return the value ``__file__`` would be set to if the specified module
|
|
|
|
was imported. Raise :exc:`ZipImportError` if the module couldn't be
|
2020-12-18 20:09:54 -04:00
|
|
|
imported.
|
2009-02-07 23:37:27 -04:00
|
|
|
|
2010-08-17 12:07:14 -03:00
|
|
|
.. versionadded:: 3.1
|
2009-02-07 23:37:27 -04:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: get_source(fullname)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Return the source code for the specified module. Raise
|
|
|
|
:exc:`ZipImportError` if the module couldn't be found, return
|
|
|
|
:const:`None` if the archive does contain the module, but has no source
|
|
|
|
for it.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: is_package(fullname)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-11-29 06:17:13 -04:00
|
|
|
Return ``True`` if the module specified by *fullname* is a package. Raise
|
2008-04-24 22:59:09 -03:00
|
|
|
:exc:`ZipImportError` if the module couldn't be found.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. method:: load_module(fullname)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
Load the module specified by *fullname*. *fullname* must be the fully
|
2020-12-18 20:09:54 -04:00
|
|
|
qualified (dotted) module name. Returns the imported module on success,
|
|
|
|
raises :exc:`ZipImportError` on failure.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2020-11-13 19:14:58 -04:00
|
|
|
.. deprecated:: 3.10
|
|
|
|
|
|
|
|
Use :meth:`exec_module` instead.
|
|
|
|
|
2021-03-08 16:06:02 -04:00
|
|
|
|
|
|
|
.. method:: invalidate_caches()
|
|
|
|
|
|
|
|
Clear out the internal cache of information about files found within
|
|
|
|
the ZIP archive.
|
|
|
|
|
|
|
|
.. versionadded:: 3.10
|
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. attribute:: archive
|
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.
........
2008-01-06 13:05:40 -04:00
|
|
|
|
Merged revisions 63066-63076,63079,63081-63085,63087-63097,63099,63101-63104 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63066 | georg.brandl | 2008-05-11 10:56:04 -0400 (Sun, 11 May 2008) | 2 lines
#2709 followup: better description of Tk's pros and cons.
........
r63067 | georg.brandl | 2008-05-11 11:05:13 -0400 (Sun, 11 May 2008) | 2 lines
#1326: document and test zipimporter.archive and zipimporter.prefix.
........
r63068 | georg.brandl | 2008-05-11 11:07:39 -0400 (Sun, 11 May 2008) | 2 lines
#2816: clarify error messages for EOF while scanning strings.
........
r63069 | georg.brandl | 2008-05-11 11:17:41 -0400 (Sun, 11 May 2008) | 3 lines
#2787: Flush stdout after writing test name, helpful when running
hanging or long-running tests. Patch by Adam Olsen.
........
r63070 | georg.brandl | 2008-05-11 11:20:16 -0400 (Sun, 11 May 2008) | 3 lines
#2803: fix wrong invocation of heappush in seldom-reached code.
Thanks to Matt Harden.
........
r63073 | benjamin.peterson | 2008-05-11 12:38:07 -0400 (Sun, 11 May 2008) | 2 lines
broaden .bzrignore
........
r63076 | andrew.kuchling | 2008-05-11 15:15:52 -0400 (Sun, 11 May 2008) | 1 line
Add message to test assertion
........
r63083 | andrew.kuchling | 2008-05-11 16:08:33 -0400 (Sun, 11 May 2008) | 1 line
Try setting HOME env.var to fix test on Win32
........
r63092 | georg.brandl | 2008-05-11 16:53:55 -0400 (Sun, 11 May 2008) | 2 lines
#2809 followup: even better split docstring.
........
r63094 | georg.brandl | 2008-05-11 17:03:42 -0400 (Sun, 11 May 2008) | 4 lines
- #2250: Exceptions raised during evaluation of names in rlcompleter's
``Completer.complete()`` method are now caught and ignored.
........
r63095 | georg.brandl | 2008-05-11 17:16:37 -0400 (Sun, 11 May 2008) | 2 lines
Clarify os.strerror()s exception behavior.
........
r63097 | georg.brandl | 2008-05-11 17:34:10 -0400 (Sun, 11 May 2008) | 2 lines
#2535: remove duplicated method.
........
r63104 | alexandre.vassalotti | 2008-05-11 19:04:27 -0400 (Sun, 11 May 2008) | 2 lines
Moved the Queue module stub in lib-old.
........
2008-05-15 21:41:41 -03:00
|
|
|
The file name of the importer's associated ZIP file, without a possible
|
|
|
|
subpath.
|
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.
........
2008-01-06 13:05:40 -04:00
|
|
|
|
|
|
|
|
2008-04-24 22:59:09 -03:00
|
|
|
.. attribute:: prefix
|
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.
........
2008-01-06 13:05:40 -04:00
|
|
|
|
Merged revisions 63066-63076,63079,63081-63085,63087-63097,63099,63101-63104 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63066 | georg.brandl | 2008-05-11 10:56:04 -0400 (Sun, 11 May 2008) | 2 lines
#2709 followup: better description of Tk's pros and cons.
........
r63067 | georg.brandl | 2008-05-11 11:05:13 -0400 (Sun, 11 May 2008) | 2 lines
#1326: document and test zipimporter.archive and zipimporter.prefix.
........
r63068 | georg.brandl | 2008-05-11 11:07:39 -0400 (Sun, 11 May 2008) | 2 lines
#2816: clarify error messages for EOF while scanning strings.
........
r63069 | georg.brandl | 2008-05-11 11:17:41 -0400 (Sun, 11 May 2008) | 3 lines
#2787: Flush stdout after writing test name, helpful when running
hanging or long-running tests. Patch by Adam Olsen.
........
r63070 | georg.brandl | 2008-05-11 11:20:16 -0400 (Sun, 11 May 2008) | 3 lines
#2803: fix wrong invocation of heappush in seldom-reached code.
Thanks to Matt Harden.
........
r63073 | benjamin.peterson | 2008-05-11 12:38:07 -0400 (Sun, 11 May 2008) | 2 lines
broaden .bzrignore
........
r63076 | andrew.kuchling | 2008-05-11 15:15:52 -0400 (Sun, 11 May 2008) | 1 line
Add message to test assertion
........
r63083 | andrew.kuchling | 2008-05-11 16:08:33 -0400 (Sun, 11 May 2008) | 1 line
Try setting HOME env.var to fix test on Win32
........
r63092 | georg.brandl | 2008-05-11 16:53:55 -0400 (Sun, 11 May 2008) | 2 lines
#2809 followup: even better split docstring.
........
r63094 | georg.brandl | 2008-05-11 17:03:42 -0400 (Sun, 11 May 2008) | 4 lines
- #2250: Exceptions raised during evaluation of names in rlcompleter's
``Completer.complete()`` method are now caught and ignored.
........
r63095 | georg.brandl | 2008-05-11 17:16:37 -0400 (Sun, 11 May 2008) | 2 lines
Clarify os.strerror()s exception behavior.
........
r63097 | georg.brandl | 2008-05-11 17:34:10 -0400 (Sun, 11 May 2008) | 2 lines
#2535: remove duplicated method.
........
r63104 | alexandre.vassalotti | 2008-05-11 19:04:27 -0400 (Sun, 11 May 2008) | 2 lines
Moved the Queue module stub in lib-old.
........
2008-05-15 21:41:41 -03:00
|
|
|
The subpath within the ZIP file where modules are searched. This is the
|
|
|
|
empty string for zipimporter objects which point to the root of the ZIP
|
|
|
|
file.
|
|
|
|
|
|
|
|
The :attr:`archive` and :attr:`prefix` attributes, when combined with a
|
|
|
|
slash, equal the original *archivepath* argument given to the
|
|
|
|
:class:`zipimporter` constructor.
|
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.
........
2008-01-06 13:05:40 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. _zipimport-examples:
|
|
|
|
|
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.
........
2008-01-06 13:05:40 -04:00
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
Here is an example that imports a module from a ZIP archive - note that the
|
2016-07-26 06:18:21 -03:00
|
|
|
:mod:`zipimport` module is not explicitly used.
|
|
|
|
|
|
|
|
.. code-block:: shell-session
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-02-23 14:26:56 -04:00
|
|
|
$ unzip -l example.zip
|
|
|
|
Archive: example.zip
|
2007-08-15 11:28:22 -03:00
|
|
|
Length Date Time Name
|
|
|
|
-------- ---- ---- ----
|
|
|
|
8467 11-26-02 22:30 jwzthreading.py
|
|
|
|
-------- -------
|
|
|
|
8467 1 file
|
|
|
|
$ ./python
|
2009-01-03 17:18:54 -04:00
|
|
|
Python 2.3 (#1, Aug 1 2003, 19:54:32)
|
2007-08-15 11:28:22 -03:00
|
|
|
>>> import sys
|
2013-02-23 14:26:56 -04:00
|
|
|
>>> sys.path.insert(0, 'example.zip') # Add .zip file to front of path
|
2007-08-15 11:28:22 -03:00
|
|
|
>>> import jwzthreading
|
|
|
|
>>> jwzthreading.__file__
|
2013-02-23 14:26:56 -04:00
|
|
|
'example.zip/jwzthreading.py'
|