Python Packages (And Modules!) Explained
If you’ve ever opened a text file and written Python code in it, you’ve created a module! A module is a file with a
.pyextension that can be imported into other modules, run by itself, or both.
Packages are collections of modules that you create and use.
You may have seen
if __name__ == '__main__'in a few Python modules.__name__is usually the variable holding the name of the module itself (so if you had a module calledmusic.py, name would holdmusic.) However, if you’re running the module directly through thepythoncommand or some other means,__name__will be__main__instead. So when you see thatifstatement, it means that that block of code will only run if this module is being run directly (i.e. not imported.)