Search notes:

Python import system: Using the -m command line option

The command line option -m runs a module as a script. If the module is a package (that is essentially a directory), it runs (or tries to run) __main__.py.
This is demonstrated with the following simple example: A directory, named minusM, contains three files:
Their content is one print() statement only: __init__.py:
print('minusM: __init__.py')
Github repository about-Python, path: /import-system/minusM/__init__.py
__main__.py:
print('minusM: __main__.py')
Github repository about-Python, path: /import-system/minusM/__main__.py
__mod__.py:
print('minusM.mod')
Github repository about-Python, path: /import-system/minusM/mod.py
If the Python interpreter is started in the directory that contains minusM like so:
python -m minusM
the following is printed:
minusM: __init__.py
minusM: __main__.py
If the interpreter is started like so:
python -m minusM.mod
this is printed:
minusM: __init__.py
minusM.mod

Index