[2013-01-05] Python boolean value of an object

This is helpfull if want to use Mock-objects in Case an Object is not available, but still want to know if a real object is available or not. I found the solution at stackoverflow.

class Foo(object):
    def __init__(self, bar):
        self.bar = bar
    def __nonzero__(self):
        return self.bar % 2 == 0