Source From Here
Question
How do you set/get the values of attributes of t given by x.
How-To
There is built-in functions called getattr and setattr:
For example:
Question
How do you set/get the values of attributes of t given by x.
- class test():
- attr1 = int
- attr2 = int
- t = test()
- x = "attr1"
There is built-in functions called getattr and setattr:
- getattr(object, attrname)
- setattr(object, attrname, value)
沒有留言:
張貼留言