Executing modules with runpy in Python


Python tip:

You can use runpy to run a module without importing it first. It works the same as the -m command line option.

An example👇

######## example.py ########
print("I am an example")

######## run_example.py ########
import runpy

runpy.run_module(mod_name="example")  # to run module example.py

# -> I am an example