Is there any advantage to using a main() in python scripts?

Chris Angelico rosuav at gmail.com
Wed Dec 11 10:49:23 EST 2013


On Thu, Dec 12, 2013 at 2:42 AM, bob gailer <bgailer at gmail.com> wrote:
> It also ensures that the defining all the classes and functions happens
> before referencing them (less "bookkeeping" for me).
>
> These two allow me to write the main program first, and follow it with all
> the global stuff.

I prefer define-before-use for readability, even if it doesn't matter
to the language. It means that locating the source of something can be
found by going upward (or starting at the top and going down - first
hit should be the definition), and helps keep things organized.
Obviously it's not always possible (mutual recursion, for instance),
but it's a general rule of thumb that I like to maintain.

ChrisA



More information about the Python-list mailing list