I am porting code from Python 2 to 3. The Python 2 version uses this snippet to instantiate a class successfully:
#at this point, "module_name" is just a string
module = __import__(module_name, globals(), locals(), [])
#class_name is just a string
my_class = getattr(module, class_name)
class_instance = my_class()
In Python 3, that same code fails with an AttributeError, saying that my module name has no attribute of my class name. The other similar questions I've read here suggest that getattr should work for this task in Python 3, but it doesn't for me.
What am I misunderstanding? Is there a better way to instantiate a class from a string?