not in
Hans Nowak
wurmy at earthlink.net
Mon Jan 21 21:24:31 EST 2002
Alex Martelli wrote:
> Why should it be OK to have both > and <=, even though
> (a <= b) is always identical to not (a > b), but somehow not ok
> to have both is and is not, because (a is not b) is always
> identical to not (a is b)?
No, the real reason the <= operator is there is that it can
be used to emulate assignment:
>>> class Foo:
def __init__(self, value):
self.value = value
def __le__(self, other):
self.value = other # !
return None
def __repr__(self):
return "Foo(%s)" % `self.value`
>>> f = Foo(1)
>>> f
Foo(1)
>>> f <= "hello"
>>> f
Foo('hello')
>>> f <= [1, 2, 3]
>>> f
Foo([1, 2, 3])
I'm going to write a PEP for this soon, so people can
finally define their own assignment operator, starting
in 2.3! I hear Guido likes the idea, and wants to adopt
this behavior for <= for all built-in objects.
This would admittely break some existing code, but it's
nothing a __future__ statement cannot handle. The old,
obsolete comparison can still be had using 'not' and '>'.
Running-for-cover-ly y'rs,
--Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA==')
# decode for email address ;-)
Site:: http://www.awaretek.com/nowak/
More information about the Python-list
mailing list