why a main() function?

anton.list at gmail.com anton.list at gmail.com
Wed Sep 20 00:07:29 EDT 2006

beliavsky at aol.com wrote:
> I think I read a suggestion somewhere to wrap the code where a Python
> script starts in a main() function, so one has


> What are the advantages of doing this?

Others have stated all the good ones, so I'll state a slightly dumber
one for us part time amateur hackers :)

If you start off writing all your python module inside a main function
then as you chop your code up into other functions (refactoring), the
code inside main is already at the proper indentation level for the new
top level functions. No more indenting it one level further to  suit
the functions indentation.


More information about the Python-list mailing list