The basic set-up is:
class A():
def __init__(self):
self.var = 1
@staticmethod
def do_stuff_with_var(self): # A method which uses self.var
...
class B(A):
def __init__(self):
A.__init__(self)
b1 = B()
b2 = B()
list_of_B_instances = [b1, b2]
for instance in list_of_B_instances:
instance.do_stuff_with_var(instance)
However the last line of code raises the following error:
AttributeError: class B has no attribute 'var'
Why is this so? I thought that a subclass inherited all data attributes from its superclass. Or is this error raised because the list_of_B_instances
does not actually contain the B objects themselves, but rather references those objects?
Keep in mind that not only am I new to Python, but I am also new to programming in general, and for that reason, you may have to dumb things down a bit for me to understand them.