Let's say I have a class like this
class MyClass(AnotherClass):
def __init__(self, arg1, arg2):
self.arg1 = arg1
self.arg2 = arg2
def f(self):
#dostuff
And I have the string "my class"
str = "my class"
I can do this:
class_name_from_str = str.title().replace(" ", "") # now class_name_from_str is "MyClass"
How could I make class_name_from_str callable? I want something like this:
callable_obj = some_process(class_name_from_str)
o = callable_obj(arg1, arg2)
o.f()
I'm using Python 2.7, by the way
UPDATE: As Matti Virkkunen suggested in a comment, a good solution is to create a dict to map strings with classes
my_calls_dict = {'my class' : MyClass, 'my other class' : MyOtherClass}