__main__ : What is this?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Oct 20 04:25:45 CEST 2007


En Fri, 19 Oct 2007 21:26:22 -0300, Matimus <mccredie at gmail.com> escribió:

> The common pattern:
>
> if __name__ == "__main__":
>   # do stuff
>
> IMHO better written:
>
> if "__main__" == __name__:
>     # do stuff

I'm intrigued why do you feel the second alternative is better.
Which is your native language? In English (and Spanish, and many others  
but still not in the majority) the usual ordering is "subject-verb-object"  
or SVO, which matches the first alternative: "If the name is __main__, do  
this..."
As all the languages I know (not so many!) are SVO, I can't think of any  
equivalent of the second form [that I could say it's better than the first]

-- 
Gabriel Genellina




More information about the Python-list mailing list