I have the following code in module xyz:
Class Outer:
Class Nested:
pass
I can successfully instantiate Outer
objects as follows
module = __import__("xyz", fromlist=[''])
the_class = getattr(module, "Outer")
instance = the_class()
However, when I replace "Outer"
with "Outer.Nested"
I get:
AttributeError: module 'xyz' has no attribute Outer.Nested
How can one make this work?
I should perhaps clarify that the above code is being used to instantiate classes whose type is unknown until runtime. Obviously I am not looking for instance = Outer.Nested()
.