I want to access a class variable defined in the parent class constructor. Here is the code.
class A(object):
def __init__(self):
x = 0
class B(A):
def __init__(self):
super(B, self).__init__()
def func(self):
print self.x
s = B()
s.func()
This gives me error:
AttributeError: 'B' object has no attribute 'x'
If I try changing the func() to
def func(self):
print x
then I get error:
NameError: global name 'x' is not defined
If I try changing the func() to
def func(self):
print A.x
Then I get the error
AttributeError: type object 'A' has no attribute 'x'
Now I am running out of ideas.. What's the correct way to access that class variable x in the parent class A? Thanks!
NOTE: I am working only on the "class B" part of my project, hence I can't really go modify class A and change the way variables are defined. That's the only constraint.
xis not a class variable.