Dynamic Multiple Inheritance In Python
I'm having a combination of 'backend' together with a 'type'. Backends: Cloudant, ElasticSearch, File, ZODB Types: News, (potentially others) So I'm now defining classes like: Plug
Solution 1:
I'm not sure I have fully understood your question, however you can "dynamically" construct class objects using the type
builtin. The following two lines produce the same result:
classPluginCloudantNews(PluginCloudant, PluginNews): pass
PluginCloudantNews = type('PluginCloudantNews', (PluginCloudant, PluginNews), {})
As you can see, type()
takes three arguments: the name of the new class, a list of base classes to inherit from, a dictionary with the attributes to add to the new class.
Post a Comment for "Dynamic Multiple Inheritance In Python"