Defining “boolness” of a class in python
For Python 2-3 compatibility, add a line after the class definition block to alias the method: class Foo(object): … Foo.__nonzero__ = Foo.__bool__ or include the alias directly in the class definition: class Foo(object): def __bool__(self): … __nonzero__ = __bool__ Of course this would also work the other way around, but I think the name __nonzero__ … Read more