I want use a class master to control status flag to every class which I want to maintain.
But I only find one way to dynamic add function and var like below.(staticmethod and classmethod don't work)
In my case,simple variable like integer ,float,bool can't call by object sharing
I do some research from link below, there are two ways to overcome this problem => one element list or self-defined class
Passing an integer by reference in Python
I wish can find a way perfectly inheritance just like class A(Master):
or instance_a = A(),some_fun(instance_a,Master)
help me to inheritance when creat instance
Do any one know how to achieve that
class A():
pass
class Master():
g_list = []
g_var = 0
def test_method(self,val):
print('test',val)
m_attr_list = [i for i in Master.__dict__.keys() if not i.startswith('__')]
for name in m_attr_list:
setattr(A, name, getattr( Master, name))