title: Is it possible to increment/access a class variable from inside a constructor in Python?
body: <p>I want to keep track via a counter, every time a class is instantiated.  I was trying to do this by incrementing a counter defined as a class variable from inside the class' consructor ala:</p>
  
  <pre><code>class Cl:
     cntr = 0
     def __init__(self):
        cntr += 1
  </code></pre>
  
  <p>However, when I instantiate the class, I get an "UnboundLocalError: local variable 'cntr' referenced before assignement" I'm assuming this is because the constructor is treating it as a local variable.  How do I reference the class variable from inside a method or constructor in Python 2.7?</p>