When writing scripts for personal use, I got used to this:
def do_something():
if __name__ == '__main__':
do_something()
Or we can also do this:
def do_something():
do_something()
I know that the first form is useful in differentiating between importing a script as a module or calling it directly, but otherwise for scripts that will be executed (and never imported), is there any reason to prefer one of them to the other?
source
share