Python: Dynamically call function within abstract class -
i have class instance needs call analyse method. constructor receives request object kind of message { "message":{ "attributes":{ "message_id":"2aj78h98-2112-4637-76h1-09ec727933bb", "topic":"mytopic", "version":1 }, "data":"{"id": 123541234}" } } my_model = mymodel(request) my_model.analyse(data) the structure of class mymodel is: import importlib class mymodel(object): def __init__(self, req): """ request, extract topic , dynamically create instance """ try: self.req = req classname = self.req.topic # in example: mytopic classpath = 'foo.bar' module = importlib.import_module(classpath) self.some_object = getattr(module, classname) except exception e: ...