I am trying to import a class from a file with a dynamic name. Here is my file importer:
def get_channel_module(app, method):
mod_name = 'channel.%s.%s' % (app, method)
module = __import__(mod_name, globals(), locals(), [method])
return module
This imports the specific python file, for example, some_file.py, which looks like this:
class SomeClassA(BaseClass):
def __init__(self, *args, **kwargs):
return
class SomeClassB():
def __init__(self, *args, **kwargs):
return
What I want to do is return only the class which extends BaseClass from the imported file, so in this instance, SomeClassA. Is there any way to do this?
You can do this by inspecting the symbols in your module with
issubclass: