On this page
runpy.run_module
Up: runpy | Next: runpy.run_path
Rel: runpy.run_path
Ref: docs.python.org — runpy.run_module
Tags: #public #python3 #stdlib #runpy
Import
import runpy
from runpy import run_module
Signature & Overview
runpy.run_module(mod_name, init_globals=None, run_name=None, alter_sys=False)
Execute a module's code without importing it.
Usage
import runpy
# Runs a module by dotted name (same as `python3 -m <mod>`) and returns its globals dict
ns = runpy.run_module("colorsys")
assert "rgb_to_hsv" in ns
Gotchas
- Pass
run_name='__main__'to triggerif __name__ == '__main__':blocks.
REPL Inspect
from runpy import run_module
help(run_module)
Linked from
Related notes
- tuts/python3/stdlib_module/runpy/run_path Linked here; links to this page; shared tags: #runpy, #stdlib
- tuts/python3/stdlib_module/runpy Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib
- tuts/c/stdlib/ctype/isalpha shared tags: #stdlib
- tuts/c/stdlib/ctype/isdigit shared tags: #stdlib
- tuts/c/stdlib/ctype/isspace shared tags: #stdlib