I’m trying to print cards using their suit unicode character and their values. I tried doing to following:
def __str__(self):
return u'\u2660'.encode('utf-8')
like suggested in another thread, but I keep getting errors saying UnicodeEncodeError: ascii, ♠, 0, 1, ordinal not in range(128). What can I do to get those suit character to show up when I print a list of cards?
Where does that
UnicodeEncodeErroroccur exactly? I can think about two possible issues here:The
UnicodeEncodeErroroccurs in you__unicode__method.Your
__unicode__method returns a byte string instead of a unicode object and that byte string contains non-ASCII characters.Do you have a
__unicode__method in your class?I tried this on the Python console according to the actual data from your comment:
It seems to work. Could you please try to print the same on your console? Maybe your console encoding is the problem.