How to get class object from class name string in the same module?
import sys
getattr(sys.modules[__name__], "Foo")
# or
globals()['Foo']
You can do it with help of the sys
module:
import sys
def str2Class(str):
return getattr(sys.modules[__name__], str)
globals()[class_name]
Note that if this isn't strictly necessary, you may want to refactor your code to not use it.