Skip to content Skip to sidebar Skip to footer

How To Overload Python's __bool__ Method?

Possible Duplicate: defining “boolness” of a class in python I thought this should print 'False', why is it printing 'True'? >>> class Foo(object): ... def __bool

Solution 1:

You should define __nonzero__() in Python 2.x. It was only renamed to __bool__() in Python 3.x. (The name __nonzero__() actually predates the introduction of the bool type by many years.)


Post a Comment for "How To Overload Python's __bool__ Method?"