Lines Matching +full:import +full:- +full:module
1 :mod:`imp` --- Access the :ref:`import <importsystem>` internals
4 .. module:: imp
5 :synopsis: Access the implementation of the import statement.
10 .. deprecated-removed:: 3.4 3.12
11 The :mod:`imp` module is deprecated in favor of :mod:`importlib`.
13 .. index:: statement: import
15 --------------
17 This module provides an interface to the mechanisms used to implement the
18 :keyword:`import` statement. It defines the following constants and functions:
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
49 Try to find the module *name*. If *path* is omitted or ``None``, the list of
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`),
61 If search is successful, the return value is a 3-element tuple ``(file,
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
75 If the module is a package, *file* is ``None``, *pathname* is the package
78 This function does not handle hierarchical module names (names containing
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
101 the module is a package or not being loaded from a file. The *description*
103 what kind of module must be loaded.
105 If the load is successful, the return value is the module object; otherwise,
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
137 edited the module source file using an external editor and want to try out 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
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
160 When a module is reloaded, its dictionary (containing the module's global
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
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
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
229 ``/foo/bar/__pycache__/baz.cpython-32.pyc`` the returned path would be
253 The following functions help interact with the import system's internal
261 Return ``True`` if the global import lock is currently held, else
264 On platforms with threads, a thread executing an import first holds a
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
267 the original import completes, preventing other threads from seeing
268 incomplete module objects constructed by the original thread. An
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.
282 Acquire the interpreter's global import lock for the current thread.
283 This lock should be used by import hooks to ensure thread-safety when
286 Once a thread has acquired the import lock, the same thread may acquire it
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.
302 Release the interpreter's global import lock. On platforms without
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
370 This method always returns ``None``, indicating that the requested module could
381 .. _examples-imp:
384 --------
386 The following function emulates what was the standard import statement up to
387 Python 1.4 (no hierarchical module names). (This *implementation* wouldn't work
391 import imp
392 import sys
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.