有人知道我在下面的代码中做错了什么吗?
ZeroList = ["53", "52", "24", "26", "36", "37", "40", "41", "43", "44", "45"]
for ZeroID in ZeroList:
if row[ZeroID]:
R+str(ZeroID) = float(row[ZeroID])
else:
R+ZeroID = 0
执行以下输出:
print R53
print R52
print R24
会输出:
2392.118329
232.298323
142.521513
我尝试了几个选项来尝试创建动态字符串,在上面的示例中,我尝试了两种方法。
有任何想法吗?
编辑
ZeroList = {"R53": "", "R52": "", "R24": "", "R26": "", "R36": "", "R37": "", "R40": "", "R41": "", "R43": "", "R44": "", "R45": ""}
for ZeroID in ZeroList:
if row[int(ZeroID[-2:])]:
ZeroList[ZeroID] = float(row[int(ZeroID[-2:])])
else:
ZeroList[RZeroID] = 0
datatoapp = [row[0], row[1], row[8], row[9], '{0:0.2f}'.format(float(ZeroList[R52]))]