if the else short form

Hrvoje Niksic hniksic at xemacs.org
Sun Oct 10 18:31:29 EDT 2010


Antoon Pardon <Antoon.Pardon at rece.vub.ac.be> writes:

> Personaly I don't see a reason to declare in advance that someone
> who wants to treat "True" differently from non-zero numbers or
> non-empty sequences and does so by a test like:
>
>   if var == True    or    if var is True
>
> to have written incorrect code.

I wouldn't call it a priori incorrect, but breaking well-established
idioms is like a SHOULD NOT thing in RFC's; you can do that, but you'd
better have a really good reason.

In the case of the gtk code OP quoted, I highly doubt that the author
wanted to special-case True in the way you describe.  It is much more
likely that he made a mistake which happened to work because he never
tested the code with a true value that evalues != 1.



More information about the Python-list mailing list