What is the idiomatic Python equivalent of this C/C++ code?
void foo() { static int counter = 0; counter++;
A static variable inside a Python method
class Count: def foo(self): try: self.foo.__func__.counter += 1 except AttributeError: self.foo.__func__.counter = 1 print self.foo.__func__.counter m = Count() m.foo() # 1 m.foo() # 2 m.foo() # 3