This allows a python script to be imported or run standalone is a sane way.
If you run a python file directly, the __name__
variable will contain __main__
. If you import the script that will not be the case. Normally, if you import the script you want to call functions or reference classes from the file.
If you did not have this check, any code that was not in a class or function would run when you import.