python : how to access object attribute given string corresponding to name of that attribute ?

Posted by Rohit on Stack Overflow See other posts from Stack Overflow or by Rohit
Published on 2010-04-10T07:22:52Z Indexed on 2010/04/10 7:33 UTC
Read the original article Hit count: 263

Filed under:
|
|
class test():
   attr1 = int
   attr2 = int

t = test()
x = "attr1"

I want to set/get value of attribute of t corresponding to x.
How do i do that ?
Thanks in advance.

© Stack Overflow or respective owner

Related posts about python

Related posts about object