Usage of main()

Manuel Graune manuel.graune at koeln.de
Fri Sep 4 03:17:31 EDT 2009


Sean DiZazzo <half.italian at gmail.com> writes:

> I'm trying to come up with an answer for you, but I can't...
>
> The if __name__ == "__main__": idiom *is* the standard way to write
> python programs, but it's not there to speed up programs.  It's there
> so that your program can be executed differently whether it is called
> as a runnable script from the command line, or if it is imported.
<SNIP>

thanks for your answer. What you are explaining is exactly why I tried
it in the first place. I'm just wondering why (this is my impression,
not necessaryly the reallity) none of the recommended texts on python
put this in the first chapters. Instead - if it is mentioned at all -
it is hidden somewhere in the "advanced" sections. Even if the reason
for this is (I'm guessing...) because it is thought to be to complicated
to explain the "why" right at the beginning, it probably would not hurt
to just tell that this is the "correct" way of doing things right at the
start and add a footnote.

Regards,

Manuel


-- 
A hundred men did the rational thing. The sum of those rational choices was
called panic. Neal Stephenson -- System of the world
http://www.graune.org/GnuPG_pubkey.asc
Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A  5828 5476 7E92 2DB4 3C99



More information about the Python-list mailing list