Understanding the if __name__ == '__main__' Syntax
Syntax:
It can also be imported:
Understanding the syntax
the variable has underscores in order to not be easy to overwrite by accident
When you run the file directly the
__name__
variable is assigned the__main__
valueBasically if it is defined then it runs the instructions
If the
if __name__ == '__main__'
is not specified then it will run the file as isFor the above case it will run
run
,shut_down
,email_admin
Last updated