title: Python: How to count the number of objects created?
body: <p>I'm new to Python. My question is, what is the best way to count the number of python objects for keeping track of number of objects exist at any given time? I thought of using a static variable.</p>
  
  <p>I have read several Q &amp; A on static variables of Python, but I could not figure out how I could achieve object counting using statics.</p>
  
  <p>My attempt was like this(below), from my C++ background I was expecting this to work but it didn't. Iis not <code>iMenuNumber</code> a static member and it should get incremented every time an object is created?</p>
  
  <pre><code>class baseMENUS:
      """A class used to display a Menu"""
  
      iMenuNumber = 0
  
      def __init__ (self, iSize):
          self.iMenuNumber = self.iMenuNumber + 1
          self.iMenuSize = iSize
  
  def main():
     objAutoTester = baseMENUS(MENU_SIZE_1)
     ....
     ....
     ....
     objRunATest = baseMENUS(MENU_SIZE_2)
  </code></pre>
  
  <p>I'm yet to write the delete(<strong>del</strong>) function(destructor).</p>