I want to add a list as a Python class instance attribute (i.e. not a class attribute), and then add a class method which will append items to the list.
e.g. we have an Employee class and each employee may have won different awards which will be stored in a list.
class Employee:
def __init__(self, name, salary):
self.name = name
self.salary = salary
employeeAwards = []
def addAward(self, Award):
employeeAwards.append(Award)
However if do this, I get an "unresolved reference" error on the instance attribute (employeeAwards).
Where should I declare the class instance attribute?
self.employeeAwards = []and thenself.employeeAwards.append(Award)