不确定如何解决这个问题?我对.format知之甚少,我正在使用:
printedxrows = [ ("[X]","[X]","[X]","[X]","[X]"," <- V: {} TOTAL: {}")
.format(row.count(0), sum(row))
for row in rows ]
我收到此错误:
for row in rows ]
AttributeError: 'tuple' object has no attribute 'format'
答案 0 :(得分:1)
("[X]","[X]","[X]","[X]","[X]"," <- V: {} TOTAL: {}")
是一个元组,而不是字符串。
你想在这里的最后一个元素上调用str.format()
,这是一个字符串对象:
("[X]", "[X]", "[X]", "[X]", "[X]", " <- V: {} TOTAL: {}".format(row.count(0), sum(row)))