`__name__` is a variable automatically set in an executing python program. If you `import` your module from another program, `__name__` will be set to the name of the module. If you run your program directly, `__name__` will be set to `__main__`.
Therefore, if you want some things to happen *only* if you're running your program from the command line and not when imported (eg. unit tests for a library)
if __name__ == "__main__":
# will run only if module directly run
print "I am being run directly"
else:
# will run only if module imported
print "I am being imported"
and if you get rid of the `if name == "main":`, and directly run the four functions
so it means that these functions will execute either you run this script file directly or import this file to another script file.
For reference and more details please see [this][1]:
[1]: https://stackoverflow.com/questions/419163/what-does-if-name-main-do
`__name__` is a variable automatically set in an executing python program. If you `import` your module from another program, `__name__` will be set to the name of the module. If you run your program directly, `__name__` will be set to `__main__`.
Therefore, if you want some things to happen *only* if you're running your program from the command line and not when imported (eg. unit tests for a library), you can use the
if __name__ == "__main__":
# will run only if module directly run
print "I am being run directly"
else:
# will run only if module imported
print "I am being imported"
trick. It's a common Python idiom.