Usage of main()

Simon Brunning simon at
Fri Sep 4 08:39:32 CEST 2009

2009/9/4 Manuel Graune <manuel.graune at>:
> How come the main()-idiom is not "the standard way" of writing a
> python-program (like e.g. in C)?

Speaking for myself, it *is* the standard way to structure a script. I
find it more readable, since I can put my main function at the very
top where it's visible, with the classes and functions it makes use of
following in some logical sequence.

I suspect that this is the case for many real-world scripts. Perhaps
it's mainly in books and demos where the extra stuff is left out so
the reader can focus on what the writer is demonstrating?

> And in addition: Can someone please explain why the first version
> is so much slower?

Access to globals is slower than access to a function's locals.

Simon B.

More information about the Python-list mailing list