My requirement is to dynamically instantiate a class based on particular strings. The catch over here is that new class has inheritance on some other classes. The issue is that I am not able to see the code getting executed from the Inherited class.
I have tried to do this by having a class as SystemConfigure
which will call the particular class based on the parameters given in a dict. In my code I am dynamically calling the Super Class which inherits functions from the Base
class. I don't see the code in the Base
class getting executed.
Please let me know how can this be done.
Code
class SystemConfigure():
def __init__(self,snp_dict):
dict = snp_dict
osname = dict['osname']
protocol = dict['protocol']
module = protocol
func_string = osname + "_" + protocol + "_" + "Configure"
print ("You have called the Class:", module, "and the function:", func_string)
m = globals()[module]
func = getattr(m, func_string)
func(dict)
class Base():
def __init__(self):
pass
print("BASE INIT")
def Unix_Base_Configure(dict):
print ("GOT IN THE UNIX BASE CLASS FUNCTION")
def Linux_Base_Configure(dict):
print("GOT IN THE LINUX BASE CLASS FUNCTION")
class Super(Base):
def __init__(self):
dict = dict
Base.__init__(self)
Base.Unix_Base_Configure(dict)
def Unix_Super_Configure(dict):
print ("GOT IN THE UNIX SUPER CLASS FUNCTION", dict)
n = SystemConfigure({'protocol':'Super','osname':'Unix','device':'dut'})
Output
You have called the Class: Super and the function: Unix_Super_Configure
GOT IN THE UNIX SUPER CLASS FUNCTION {'protocol': 'Super', 'osname': 'Unix', 'device': 'dut'}
Expectation
I was expecting the "GOT IN THE UNIX BASE CLASS FUNCTION" error to be printed. The output needs to be printed before the "GOT IN THE UNIX SUPER CLASS FUNCTION" message.