On Sun, 25 Jan 2009 03:07:04 +0200, Oktay Şafak wrote:
The reason is that when
someone writes (-1 == True) he is clearly, definitely, absolutely asking
for a boolean comparison, not a numerical one.
If I wrote (-1 == True), and I'm not sure why I would, I would expect to
get the answer
Hi all,
I ran into a strange case.
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32
...
>>> -1 == True
False
>>> -1 == False
False
This works though:
>>> if -1:
print "OK"
OK
After some head scratching, I realized that:
- bool is a subclass of int and
On 2009-01-24 17:00, oktaysa...@superonline.com wrote:
Hi all,
I ran into a strange case.
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
...
-1 == True
False
-1 == False
False
This works though:
if -1:
print OK
OK
After some head scratching, I
Robert Kern wrote:
On 2009-01-24 17:00, oktaysa...@superonline.com wrote:
Hi all,
I ran into a strange case.
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
...
-1 == True
False
-1 == False
False
This works though:
if -1:
print OK
OK
After some
oktaysa...@superonline.com wrote:
Hi all,
I ran into a strange case.
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
...
-1 == True
False
-1 == False
False
This works though:
if -1:
print OK
OK
After some head scratching, I realized that:
-
On 2009-01-24 19:07, Oktay Şafak wrote:
Robert Kern wrote:
On 2009-01-24 17:00, oktaysa...@superonline.com wrote:
Hi all,
I ran into a strange case.
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
...
-1 == True
False
-1 == False
False
This works
Oktay Şafak wrote:
That's what I'm trying to say: it would be more meaningful if int.__eq__
did a boolean comparison when the other operand is a boolean.
For that to be done, int would have to know about its subclass, which
generally is bad design.
The reason is that when
someone writes
I don't see how fixing this makes harder to treat True and False as
first-class objects. If doing the right thing takes some special casing
then be it, but I don't think it's so.
True in ['something', False]
In your semantics, this would evaluate to True because ('something' ==
True) is True.
Terry Reedy wrote:
Oktay Şafak wrote:
That's what I'm trying to say: it would be more meaningful if
int.__eq__ did a boolean comparison when the other operand is a boolean.
For that to be done, int would have to know about its subclass, which
generally is bad design.
Good point, but of