about if __name == '__main__':

woooee woooee at gmail.com
Sun Aug 28 14:56:40 EDT 2011

Two main routines, __main__ and main(), is not the usual or the common
way to do it.  It is confusing and anyone looking at the end of the
program for statements executed when the program is called will find
an isolated call to main(), and then have to search the program for
the statements that should have been at the bottom of the program.
The only reason to use such a technique in Python is if you want to
call the function if the program is run from the command line, and
also call the same function if the program is imported from another.
In which case, use a name that is descriptive, not "main".  And be
careful of anyone that gives you programming advice.  Research these
things for yourself.

More information about the Python-list mailing list