Running python modules


project/
�
+-- mypackage/
�   +-- __init__.py
�   +-- mymodule.py
�
+-- myscript.py
  1. myscrip.py is called a script
  2. mymodule.py is also a script (and also sometimes referred to as a module)

# Running a script with full path
python /somepath/project/myscript.py

# Running a script as a module.
# Notice no .py in the end nor the path
python -m mypackage.module

# Using only the package
# In this case there has to be a file called __main__.py
python -m mypackage

# the __name__ is set to __main__ in that script or module

# So the following code segment is useful

if __name__ == '__main__':
    localTest()
  1. Searches the module path to locate the module
  2. So full path is not necessary