I have class A
inside module consumers\a
, B
inside consumers\a
and C
inside consumers\c
. I have used the following code to fetch the classes. Is there any other way to achieve the same. (this will work only if the class_name.lower() == module_name
).
bridge.py
import inspect
import types
from consumers import a
from consumers import b
from consumers import c
for name, val in globals().items():
if isinstance(val, types.ModuleType):
if 'consumers' in val.__name__:
for k, v in inspect.getmembers(val):
if k.lower() == name:
v()
I am trying this because I don't want the successor to do lot of work to add consumer.
I read, how-can-i-get-a-list-of-all-classes-within-current-module-in-python, /how-do-you-get-all-classes-defined-in-a-module-but-not-imported and few more links and came up with the above solution.