title: How to return a value when destroying/cleaning-up an object instance
body: <p>When I initiate a class in Python, I give it some values. I then call method in the class which does something. Here's a snippet:</p>
  
  <pre><code>class TestClass():
      def __init__(self):
         self.counter = 0
  
      def doSomething(self):
          self.counter = self.counter + 1
          print 'Hiya'
  
  if __name__ == "__main__":
      obj = TestClass()
      obj.doSomething()
      obj.doSomething()
      obj.doSomething()
      print obj.counter
  </code></pre>
  
  <p>As you can see, everytime I call the <code>doSomething</code> method, it prints some text and increments an internal variable i.e. counter. When I initiate the class, i set the counter variable to 0. When I destroy the object, I'd like to return the internal <code>counter</code> variable. What would be a good way of doing this? I wanted to know if there were other ways apart from doing stuff like:</p>
  
  <ul>
  <li>accessing the variable directly. Like <code>obj.counter</code>.</li>
  <li>creating a method like <code>getCounter</code>.</li>
  </ul>
  
  <p>Thanks.</p>