Source

sphinx / Doc-3k / library / runpy.rst

Full commit

:mod:`runpy` --- Locating and executing Python modules

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.

When executed as a script, the module effectively operates as follows:

del sys.argv[0]  # Remove the runpy module from the arguments
run_module(sys.argv[0], run_name="__main__", alter_sys=True)

The :mod:`runpy` module provides a single function: