• Home
  • Raw
  • Download

Lines Matching +full:is +full:- +full:module

1 :mod:`imp` --- Access the :ref:`import <importsystem>` internals
4 .. module:: imp
10 .. deprecated-removed:: 3.4 3.12
11 The :mod:`imp` module is deprecated in favor of :mod:`importlib`.
15 --------------
17 This module provides an interface to the mechanisms used to implement the
23 .. index:: pair: file; byte-code
25 Return the magic string value used to recognize byte-compiled code files
34 Return a list of 3-element tuples, each describing a particular type of
35 module. Each triple has the form ``(suffix, mode, type)``, where *suffix* is
36 a string to be appended to the module name to form the filename to search
37 for, *mode* is the mode string to pass to the built-in :func:`open` function
39 files), and *type* is the file type, which has one of the values
49 Try to find the module *name*. If *path* is omitted or ``None``, the list of
50 directory names given by ``sys.path`` is searched, but first a few special
51 places are searched: the function tries to find a built-in module with the
52 given name (:const:`C_BUILTIN`), then a frozen module (:const:`PY_FROZEN`),
56 Otherwise, *path* must be a list of directory names; each directory is
61 If search is successful, the return value is a 3-element tuple ``(file,
64 *file* is an open :term:`file object` positioned at the beginning, *pathname*
65 is the pathname of the file found, and *description* is a 3-element tuple as
67 module found.
69 If the module is built-in or frozen then *file* and *pathname* are both ``None``
71 the module type is indicated as given in parentheses above. If the search
72 is unsuccessful, :exc:`ImportError` is raised. Other exceptions indicate
75 If the module is a package, *file* is ``None``, *pathname* is the package
76 path and the last item in the *description* tuple is :const:`PKG_DIRECTORY`.
78 This function does not handle hierarchical module names (names containing
79 dots). In order to find *P.M*, that is, submodule *M* of package *P*, use
86 compatibility is required, in which case use
88 see the :ref:`importlib-examples` section of the :mod:`importlib`
94 Load a module that was previously found by :func:`find_module` (or by an
96 more than importing the module: if the module was already imported, it will
97 reload the module! The *name* argument indicates the full
98 module name (including the package name, if this is a submodule of a
99 package). The *file* argument is an open file, and *pathname* is the
101 the module is a package or not being loaded from a file. The *description*
102 argument is a tuple, as would be returned by :func:`get_suffixes`, describing
103 what kind of module must be loaded.
105 If the load is successful, the return value is the module object; otherwise,
106 an exception (usually :exc:`ImportError`) is raised.
108 **Important:** the caller is responsible for closing the *file* argument, if
109 it was not ``None``, even when an exception is raised. This is best done
119 :func:`importlib.util.module_from_spec`. See the :ref:`importlib-examples`
126 Return a new empty module object called *name*. This object is *not* inserted
133 .. function:: reload(module)
135 Reload a previously imported *module*. The argument must be a module object, so
136 it must have been successfully imported before. This is useful if you have
137 edited the module source file using an external editor and want to try out the
138 new version without leaving the Python interpreter. The return value is the
139 module object (the same as the *module* argument).
141 When ``reload(module)`` is executed:
143 * Python modules' code is recompiled and the module-level code reexecuted,
144 defining a new set of objects which are bound to names in the module's
145 dictionary. The ``init`` function of extension modules is not called a second
151 * The names in the module namespace are updated to point to any new or changed
154 * Other references to the old objects (such as names external to the module) are
156 where they occur if that is desired.
160 When a module is reloaded, its dictionary (containing the module's global
161 variables) is retained. Redefinitions of names will override the old
162 definitions, so this is generally not a problem. If the new version of a module
164 remains. This feature can be used to the module's advantage if it maintains a
165 global table or cache of objects --- with a :keyword:`try` statement it can test
173 It is legal though generally not very useful to reload built-in or dynamically
178 If a module imports objects from another module using :keyword:`from` ...
179 :keyword:`import` ..., calling :func:`reload` for the other module does not
180 redefine the objects imported from it --- one way around this is to re-execute
181 the :keyword:`!from` statement, another is to use :keyword:`!import` and qualified
182 names (*module*.*name*) instead.
184 If a module instantiates instances of a class, reloading the module that defines
185 the class does not affect the method definitions of the instances --- they
186 continue to use the old class definition. The same is true for derived classes.
189 Relies on both ``__name__`` and ``__loader__`` being defined on the module
196 The following functions are conveniences for handling :pep:`3147` byte-compiled
203 Return the :pep:`3147` path to the byte-compiled file associated with the
204 source *path*. For example, if *path* is ``/foo/bar/baz.py`` the return
205 value would be ``/foo/bar/__pycache__/baz.cpython-32.pyc`` for Python 3.2.
206 The ``cpython-32`` string comes from the current magic tag (see
207 :func:`get_tag`; if :attr:`sys.implementation.cache_tag` is not defined then
215 If :attr:`sys.implementation.cache_tag` is ``None``, then
216 :exc:`NotImplementedError` is raised.
228 file path. For example, if *path* is
229 ``/foo/bar/__pycache__/baz.cpython-32.pyc`` the returned path would be
231 to :pep:`3147` format, a :exc:`ValueError` is raised. If
232 :attr:`sys.implementation.cache_tag` is not defined,
233 :exc:`NotImplementedError` is raised.
237 :attr:`sys.implementation.cache_tag` is not defined.
261 Return ``True`` if the global import lock is currently held, else
265 global import lock, then sets up a per-module lock for the rest of the
266 import. This blocks other threads from importing the same module until
268 incomplete module objects constructed by the original thread. An
269 exception is made for circular imports, which by construction have to
270 expose an incomplete module object at some point.
273 The locking scheme has changed to per-module locks for
274 the most part. A global import lock is kept for some critical tasks,
275 such as initializing the per-module locks.
283 This lock should be used by import hooks to ensure thread-safety when
293 The locking scheme has changed to per-module locks for
294 the most part. A global import lock is kept for some critical tasks,
295 such as initializing the per-module locks.
306 The locking scheme has changed to per-module locks for
307 the most part. A global import lock is kept for some critical tasks,
308 such as initializing the per-module locks.
313 The following constants with integer values, defined in this module, are used
319 The module was found as a source file.
326 The module was found as a compiled code object file.
333 The module was found as dynamically loadable shared library.
340 The module was found as a package directory.
347 The module was found as a built-in module.
354 The module was found as a frozen module.
361 The :class:`NullImporter` type is a :pep:`302` import hook that handles
362 non-directory path strings by failing to find any modules. Calling this type
364 Otherwise, a :class:`NullImporter` instance is returned.
370 This method always returns ``None``, indicating that the requested module could
374 ``None`` is inserted into ``sys.path_importer_cache`` instead of an
381 .. _examples-imp:
384 --------
387 Python 1.4 (no hierarchical module names). (This *implementation* wouldn't work
395 # Fast path: see if the module has already been imported.
402 # there's a problem we can't handle -- let the caller handle it.