"Saizan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > John Roth wrote: > >> The not operator and the bool() builtin produce >> boolean results. Since bool is a subclass of int, >> all the integer operations will remain integer >> operations. This was done for backwards >> compatability, and is unlikely to change in the 2.x >> series. > > Ok, shame on me, I completely overlooked "not" and it surprises myself > because it's not like I haven't used it, I just didn't see "not" as an > operator, maybe because i can't find a __not__ method in bool class. > (Is it hidden somewhere or is computed in some other way?) > > (However (not x) whould be as annoying as 1-x even if a little more > readable (if you consider lispish parentheses readable): > Input expression: (not (not x)&(not y)!(not (z|v))) > Maybe direct eval is just the wrong way of doing this, I should look > for or make muParser bindings for Python instead..) > What about __nonzero__?
class IsOdd(object): def __init__(self,n): self.val = n def __nonzero__(self): return self.val % 2 for i in range(4): if IsOdd(i): print i,"is odd" else: print i,"is even" Prints: 0 is even 1 is odd 2 is even 3 is odd -- Paul -- http://mail.python.org/mailman/listinfo/python-list