pydoc > runpy

๐Ÿ“› NAME

runpy - runpy.py - locating and running Python code using the module namespace

๐Ÿš€ Quick Reference

Use CaseCommandDescription
Run a module by namerun_module('mymodule')Execute the module's code without importing it
Run a module with altered sys.argvrun_module('mypackage', alter_sys=True)Update sys.argv[0] and sys.modules during execution
Run a script from a file pathrun_path('/path/to/script.py')Execute code at the specified filesystem location
Run a script with custom globalsrun_path('script.py', init_globals={'debug': True})Pre-populate the moduleโ€™s globals dictionary

๐Ÿ”— MODULE REFERENCE

https://docs.python.org/3.10/library/runpy.html

The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.

๐Ÿ“ DESCRIPTION

Provides support for locating and running Python scripts using the Python module namespace instead of the native filesystem.

This allows Python code to play nicely with non-filesystem based PEP 302 importers when locating support scripts as well as when importing modules.

โš™๏ธ FUNCTIONS

โ–ถ๏ธ run_module(mod_name, init_globals=None, run_name=None, alter_sys=False)

Execute a module's code without importing it.

mod_name -- an absolute module name or package name.

Optional arguments:

Returns the resulting module globals dictionary.

โ–ถ๏ธ 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:

Returns the resulting module globals dictionary.

๐Ÿ—‚๏ธ DATA

__all__ = ['run_module', 'run_path']

๐Ÿ“ FILE

/usr/lib/python3.10/runpy.py

runpy
๐Ÿ“› NAME ๐Ÿš€ Quick Reference ๐Ÿ”— MODULE REFERENCE ๐Ÿ“ DESCRIPTION โš™๏ธ FUNCTIONS
โ–ถ๏ธ run_module(mod_name, init_globals=None, run_name=None, alter_sys=False) โ–ถ๏ธ run_path(path_name, init_globals=None, run_name=None)
๐Ÿ—‚๏ธ DATA ๐Ÿ“ FILE

Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 19:11 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format