我有3variable
print(obj.col1_expense.text) #test1
print(obj.col2_expense.text) #test2
print(obj.col3_expense.text) #test3
如何动态打印?
现在我这样努力
for x in range(1, 4):
print("obj.col"+str(x)+"_expense".text)
但它会产生错误
AttributeError: 'str' object has no attribute 'text'
Tags:
我希望这对你有帮助:
您可以使用[Python]: getattr(object, name[, default]):
或者,为了确保在弄乱索引的情况下不会得到
AttributeError
,可以将print
替换为此表单(不太容易阅读):我不确定,但如果你想创建变量和相应的值。 这将取决于您想在哪里使用变量。
相关问题 更多 >
编程相关推荐