redefine __and__ operator
Posted
by wiso
on Stack Overflow
See other posts from Stack Overflow
or by wiso
Published on 2010-04-19T15:29:54Z
Indexed on
2010/04/19
15:33 UTC
Read the original article
Hit count: 313
Why I can't redefine the __and__
operator?
class Cut(object):
def __init__(self, cut):
self.cut = cut
def __and__(self, other):
return Cut("(" + self.cut + ") && (" + other.cut + ")")
a = Cut("a>0")
b = cut("b>0")
c = a and b
print c.cut()
I want (a>0) && (b>0)
, but I got b, that the usual behaviour of and
© Stack Overflow or respective owner