why a main() function?
insyte at gmail.com
insyte at gmail.com
Mon Sep 18 15:49:57 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
>
> def main():
> print "hi"
>
> main()
>
> instead of
>
> print "hi"
>
> What are the advantages of doing this?
I'm sure there are other reasons, but for me the most important is that
you can import your code into the interpreter and poke at it from there
without executing the script. Also, of course, you can re-use your
code as a module in another program.
-Ben
More information about the Python-list
mailing list