Since the classes are all subclasses of _MyBase
, they can be accessed via _MyBase.__subclasses__()
after they have been imported:
for (module_loader, name, ispkg) in pkgutil.iter_modules([pkg_dir]):
importlib.import_module('.' + name, __package__)
all_my_base_classes = {cls.__name__: cls for cls in base._MyBase.__subclasses__()}
For importing the modules, I followed the advice of Nihathraelthe advice of Nihathrael.