PyDocs

Nav

Importing Modules

run_path

runpy

function · Added in 3.2 (source)
  • run_path(path_name, init_globals=None, run_name=None)
Execute code located at the specified filesystem location.

path_name -- filesystem location of a Python script, zipfile,
or directory containing a top level __main__.py script.

Optional arguments:
init_globals -- dictionary used to pre-populate the module’s
globals dictionary before the code is executed.

run_name -- if not None, this will be used to set __name__;
otherwise, '<run_path>' will be used for __name__.

Returns the resulting module globals dictionary.
Changed in 3.4, 3.12, 3.15
  • 3.4: Updated to take advantage of the module spec feature added by PEP 451. This allows __cached__ to be set correctly in the case where __main__ is imported from a valid sys.path entry rather than being executed directly.
  • 3.12: The setting of __cached__, __loader__, and __package__ are deprecated.
  • 3.15: The global variable __cached__ is no longer set.
0 Examples
No examples for runpy/run_path.
See Also
No see-alsos for runpy/run_path
0 Notes
No notes for run_path