__main__ : What is this?
Jeff
jeffober at gmail.com
Fri Oct 19 23:40:36 EDT 2007
A common pattern is to put test code in the block there, too, for
modules.
Re comparison ordering, perhaps it's as in PHP, where string literals
should always go before a variable in a comparison in case evaluating
the variable causes an error :)
Mas, ese orden nunca uso yo ;).
On Oct 19, 10:25 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Fri, 19 Oct 2007 21:26:22 -0300, Matimus <mccre... 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