Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Script or library

  • main
  • name

We can have a file with all the functions implemented and then launch the run() function only if the file was executed as a stand-alone script.

def run():
    print("run in ", __name__)

print("Name space in mymodule.py ", __name__)

if __name__ == '__main__':
    run()

$ python mymodule.py
Name space in mymodule.py  __main__
run in  __main__