Try to initialize instance variable counter to 0 in init method:
def __init__(self):
self.counter = 0
Rest of the code is ok.
More Related Contents:
- Why does it say that my instance has no attribute x?
- How to avoid having class data shared among instances?
- difference between variables inside and outside of __init__()
- What is the difference between class and instance variables?
- Is it possible to overload Python assignment?
- How can I decorate an instance method with a decorator class?
- What does “bound method” error mean when I call a function?
- What is the `self` parameter in class methods?
- Attaching a decorator to all functions within a class
- Why do attribute references act like this with Python inheritance? [duplicate]
- Possibilities for Python classes organized across files? [closed]
- How do I access Class member variables in Python?
- How do you create an incremental ID in a Python Class
- The scope of names defined in class block doesn’t extend to the methods’ blocks. Why is that?
- Python: How do I make a subclass from a superclass?
- How to implement a binary search tree in Python?
- Getting container/parent object from within python
- “__init__” vs “__call__” in python class
- class method generates “TypeError: … got multiple values for keyword argument …”
- Understanding __init_subclass__
- Should I use instance or class attributes if there will only be one instance? [closed]
- How can I choose a custom string representation for a class itself (not instances of the class)?
- Missing 1 required positional argument
- How can I dynamically create class methods for a class in python [duplicate]
- How to extend a class in python?
- Using Python class as a data container [closed]
- Python calling method in class
- How to declare a static attribute in Python?
- How to find instance of a bound method in Python?
- How to dynamically access class properties in Python?