Understanding and resolving AttributeError in Python
An AttributeError is raised when you try to use an attribute or method that an object does not have.
Common causes of this error...
# Code that causes the error
class Dog:
def __init__(self, name):
self.name = name
my_dog = Dog('Buddy')
print(my_dog.age)# Fixed code
class Dog:
def __init__(self, name, age):
self.name = name
self.age = age
my_dog = Dog('Buddy', 5)
print(my_dog.age)