blunde
blunde

Reputation: 13

TypeError: __str__ returned non-string (type tuple)

def __str__(self):
    summa = 0
    for a in self.__pisteet:
        summa += a
        mjono += str(a)
    return "{:s} {:s} yhteensa", summa, "pistetta".format(self.__nimi, mjono)  

So there are multiple players and I should be able to print all their names, all scores and the sum of scores.

TypeError: __str__ returned non-string (type tuple)

Upvotes: 1

Views: 8330

Answers (2)

jabaldonedo
jabaldonedo

Reputation: 26572

The problem is that you are not returning a string, take a look to your return statement. ',' comma operator defines a tuple it does not concatenate strings, you must return:

return "{:s} {:s} yhteensa {} pistetta".format(self.__nimi, mjono,  summa) 

Upvotes: 1

Ashwini Chaudhary
Ashwini Chaudhary

Reputation: 250931

Items separated by commas create a tuple, so you need to remove those:

return "{:s} {:s} yhteensa {} pistetta".format(self.__nimi, mjono, summa) 

Upvotes: 6

Related Questions