sname = "example"
some_class.<sname>.do_stuff()
sname is the name of a subclass in some_class. Is it possible to dynamically reference the string in my call, so some_class.example.do_stuff() is called?
asked Mar 11, 2013 at 4:20
user1814016
2,4235 gold badges27 silver badges28 bronze badges
1 Answer 1
You're looking for the getattr() builtin:
getattr(some_class, sname).do_stuff()
answered Mar 11, 2013 at 4:22
FatalError
55.1k16 gold badges106 silver badges119 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py