2
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

1 Answer 1

6

You're looking for the getattr() builtin:

getattr(some_class, sname).do_stuff()
answered Mar 11, 2013 at 4:22
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.