I have a module (myMod.py) with an Object baseObj with a few methods
class baseObj(object):
....
def doThing(self):
......
I need to create many subclasss, normal way to do this would be:
class Foo(baseObl):
pass
class Bar(baseObl):
pass
etc.
But there there are a lot of these.
I have the names of these subclasss in a list
subNames = ['Foo','Bar','Lorem',...]
I can create the subclass dynamically like so (identical to the above)
Foo = type('Foo', (baseObj), {})
What I want to do is something like:
for name in subNames:
name = type(name, (baseObj), {})
To create a bunch of subclasss with the names in the list.
Obviously, this dose not work.
What I found on line was doing something like this :
registry =[]
for name in subNames:
registry[name] = type(name, (baseObj), {})
Which will not give me the kind if API I am looking for.
What I want to allow at the end is:
from myMod import Foo, Bar
a = Foo()
a.doThing()
b = Bar()
b.doThing()
etc.
Is there a pretty way to do this?