Numbers and truth values
Szabolcs
szhorvat at gmail.com
Sat Apr 28 17:54:01 EDT 2007
Alex Martelli wrote:
> Maybe somebody assigning a value to True or False is a
> common error, but much of my livelihood over the last 10 years has been
> about mentoring/coaching programmers in Python, and that's one error I
> have *NEVER* observed, so I'd need a lot of empirical evidence to
> convince me it's worth adding two more reserved words to Python's
> reasonably short list (I feel much the same way about None, by the way).
> pychecker, pylint, and friends, are a much better way to detect and warn
> about all sort of anomalies of this kind.
Yes, I admit that it was a very stupid mistake. (Though I'm not even
sure that this is what happened. Next time I should probably sleep on
it, and try it again the next day, to avoid posting such a stupid
question again.) But note that I was using Python interactively (just
experimenting with it). It is very unlikely that someone would write
things like True == 2 without any additional context in a real program.
(Actually it is unlikely that someone would write this in any
circumstance in a real program.)
But I still think that it is an inconsistency to allow to redefine a
_value_ like True or False (not a built-in function that may have been
missing in earlier versions). Saying True = 2 is just like saying 3 = 2.
Learning about pylint was very useful (thanks for the advice!) -- it
helps in catching those kinds of errors that surface only at runtime in
Python programs, but are easily caught at compile time in compiled
languages.
More information about the Python-list
mailing list