I have a couple modules loaded on startup. Every module has a name and a send function. To access the imported modules I store them in a dict and access by the dict key.
m1 = Module1()
m2 = Module2()
modules = {m1.name: m1, m2.name: m2}
# now access a function
modules["m1_name"].send()
this approach works pretty well but seems a bit ugly to me. Is there an "official" way?
EDIT:
I define a list of priorities, say prios = ["signal", "telegram", "txt"]
, the program tries to send the message to each user of a group, always trying to use the module with highest priority.
Only modules in the prio
list will be imported.
EDIT: my import function looks like this:
for modul_name in prios:
modul_import = importlib.import_module(("modules." + modul_name))
modul = modul_import.Modul(self.inbox)
modul.start()
modules[modul_name] = modul