Reputation: 2383
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?
Upvotes: 2
Views: 66
Reputation: 54631
You're looking for the getattr()
builtin:
getattr(some_class, sname).do_stuff()
Upvotes: 6