2013-12-10 47 views
1

不知道如何解決這個問題?我知之甚少.format,和我使用:元組屬性? (Python)

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

你們是不是要產生一個字符串的元組或與它周圍的括號字符串? – dawg

回答

1

("[X]","[X]","[X]","[X]","[X]"," <- V: {} TOTAL: {}")是一個元組,而不是一個字符串。

要撥打str.format()這裏的最後一個元素,它是一個字符串對象:

("[X]", "[X]", "[X]", "[X]", "[X]", " <- V: {} TOTAL: {}".format(row.count(0), sum(row)))