Can you use self in __str__
Seymore4Head at Hotmail.invalid
Fri Nov 28 02:26:45 CET 2014
s = "Hand contains "
for x in self.hand:
s = s + str(x) + " "
This is part of a Hand class. I need a hand for the dealer and a hand
for the player.
This prints out 'Hand contains " foo bar
for both the dealer's hand and the player's hand.
Is there a way to include "self" in the __string__ so it reads
Dealer hand contains foo bar
Player hand contains foo bar
s = self + "Hand contains " and that doesn't work.
s = self + s + str(x) + " " doesn't work either
Line 60: TypeError: cannot concatenate 'str' and 'Hand' objects
s = self.hand + s + str(x) + " "
Line 60: TypeError: can only concatenate list to list
More information about the Python-list