derkyzer
derkyzer

Reputation: 161

Tuple Attributes? (Python)

Not sure how to fix this? I know little about .format, and I am using:

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

I am getting this error:

    for row in rows ]
AttributeError: 'tuple' object has no attribute 'format'

Upvotes: 1

Views: 1383

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1123970

("[X]","[X]","[X]","[X]","[X]"," <- V: {} TOTAL: {}") is a tuple, not a string.

You want to call str.format() on the last element here, which is a string object:

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

Upvotes: 1

Related Questions