You mean this test?
if __name__ == "__main__":
# faz algo
What this test determines is whether the execution is happening on main scope, i.e., it is the script that was directly executed from the command line (or from the graphical menu).
This test is useful when you want the script to be imported with a module (in which case the above test will return False) but can also be executed directly. (As a pure module only defines functions and classes, it usually does nothing even if it runs directly.)
So there is no "right" or "wrong", it can be an interesting practice to encapsulate code this way so that a script is "modularized" easily, but a script that will always run directly in the foreseeable future does not need this.
You can check the answer given and make sure you’re asking the right question?
__init__
and__name__
are completely different things.– Woss