title: Python: How to do extra stuff when a specific attribute of an object is accessed?
body: <p>Let's say I have a class in Python:</p>
  
  <pre><code>class Foo(object):
      a = 1
      b = 2
  </code></pre>
  
  <p>I'd like to do some extra stuff when I access 'a' but NOT 'b'. So, for example, let's assume that the extra stuff I'd like to do is to increment the value of the attribute:</p>
  
  <pre><code>&gt; f = Foo()
  &gt; f.a # Should output 2
  &gt; f.a # Should output 3
  &gt; f.a # Should output 4
  &gt; f.b # Should output 2, since I want the extra behavior just on 'a'
  </code></pre>
  
  <p>It feels like there is a way through __getattr__ or __getattribute__, but I couldn't figure that out.</p>
  
  <p>The extra thing can be anything, not necessarily related to the attribute (like print 'Hello world').</p>
  
  <p>Thanks.</p>