n | |
| :mod:`runpy` --- Locating and executing Python modules. |
| :mod:`runpy` --- Locating and executing Python modules |
| ======================================================= |
| ====================================================== |
| |
| .. module:: runpy |
n | :synopsis: Locate and run Python modules without importing them first. |
| .. moduleauthor:: Nick Coghlan <ncoghlan@gmail.com> |
n | |
| |
| .. % standard library, in Python |
| |
| |
| |
| .. versionadded:: 2.5 |
| |
| The :mod:`runpy` module is used to locate and run Python modules without |
| importing them first. Its main use is to implement the :option:`-m` command line |
| switch that allows scripts to be located using the Python module namespace |
| rather than the filesystem. |
| does not make filename information available, this variable is set to ``None``. |
| |
| ``__builtins__`` is automatically initialised with a reference to the top level |
| namespace of the :mod:`__builtin__` module. |
| |
| If the argument *alter_sys* is supplied and evaluates to ``True``, then |
| ``sys.argv[0]`` is updated with the value of ``__file__`` and |
| ``sys.modules[__name__]`` is updated with a temporary module object for the |
t | module being executed. Both ``sys.argv[0]`` and ``sys.modules[__name__]`` are |
t | module being executed. Both ``sys.argv[0]`` and ``sys.modules[__name__]`` |
| restored to their original values before the function returns. |
| are restored to their original values before the function returns. |
| |
| Note that this manipulation of :mod:`sys` is not thread-safe. Other threads may |
| see the partially initialised module, as well as the altered list of arguments. |
| It is recommended that the :mod:`sys` module be left alone when invoking this |
| function from threaded code. |
| |
| |
| .. seealso:: |