True inconsistency in Python
Tim Roberts
timr at probo.com
Mon Nov 17 02:58:19 EST 2003
Scott Chapman <scott_list at mischko.com> wrote:
>
>Historically Python has allowed <> 0 to equal true in evaluations. Now
><> 0 still evaluates to true in evaluations. However it doesn't equal
>True. They are not interchangable. (Same with empty lists, etc.)
Python is certainly not the only language in which this occurs. Many are
the C programmers who have been burned by:
int SomeFunction();
...
if( SomeFunction == TRUE )
{
}
Visual Basic has exactly the same problem. Further, until very recently,
True in VB actually evaulated to -1, so even comparing to "1" would fail.
This should not be a surprise. Booleans should be thought of as enumerated
integral types.
>Assuming the old behavior is desired, programmers need to be careful
>not to compare a variable with True as in:
>
>if var == True: # only works if var is 1
> blah
Your statement is absolutely true. End of story.
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list