I have a particular problem with objective python, I would like to have a configuration class (Config), so it could be used as a base class for other classes which will need configuration data. What I want do is to use this Config class to share once iniciated data among all inheriting classes. What is important for me, when class Inherit configuration data I want it to be able to use it as it owns, for ex:
class Config:
a= None
b= None
class A(Config):
def __init__(self):
a = 10
def print_a(self):
print(self.a)
And here is the first questione, how should I set values of a and b in A class? Another one is how to call them inside the class?
When I'm doing sth like this :
obj = A()
obj.a = 5
or when i add methon do A class, which sets a variable:
class A(Config):
def __init__(self):
a = 10
def print_a(self):
print(self.a)
def setA(self, val):
a = val
and call :
obj = A()
obj.setA(12)
it does not change either A.a or Config.a
To sum up, my goal is to create a class with static variables (Config), and through inheritance I would like to obtain acces to those variables from another class A(Config), and use those variables as they were native class variables. It is also important that every change in obj = A() -> obj.a should change Config.a variable (the same when I change variable a insade class A).
Its sucha a confusing idea what I want to do, hope you understand. Also I am pretty new to python so there is a lot of I dont understand yet, try to be forgiving please :).