相关疑难解决方法(0)

如何访问对应于该属性名称的给定字符串的对象属性

如何设置/获取t给定的属性值x.

class Test:
   def __init__(self):
       self.attr1 = 1
       self.attr2 = 2

t = Test()
x = "attr1"
Run Code Online (Sandbox Code Playgroud)

python attributes object

121
推荐指数
2
解决办法
7万
查看次数

标签 统计

attributes ×1

object ×1

python ×1