title: Defining "boolness" of a class in python
body: <p>Why doesn't this work as one may have naively expected?</p>
  
  <pre><code>class Foo(object):
      def __init__(self):
          self.bar = 3
      def __bool__(self):
          return self.bar &gt; 10
  
  foo = Foo()
  
  if foo:
      print 'x'
  else:
      print 'y'
  </code></pre>
  
  <p>(The output is <code>x</code>)</p>