I'm making a card game, but I've run into what seems to be an encoding issue. I'm trying to print a card like this:
def print(self):
print("|-------|")
print("| %s |" % self.value)
print("| |")
print("| %s |" % self.suit.encode("utf-8"))
print("| |")
print("| %s |" % self.value)
print("|-------|")
This is what I want:
|-------|
| 10 |
| |
| ♦ |
| |
| 10 |
|-------|
...but this is what I get:
|-------|
| 10 |
| |
| b'\xe2\x99\xa6' |
| |
| 10 |
|-------|
I'm on Windows and Python 3 if that matters.
The value of self.suit can be any of the following:
spade = "♠"
heart = "♥"
diamond = "♦"
club = "♣"
If I remove the .encode("utf-8") I get this error:
Traceback (most recent call last):
File "main.py", line 79, in <module>
start()
File "main.py", line 52, in start
play()
File "main.py", line 64, in play
card.print()
File "main.py", line 36, in print
print("| \u2660 |")
File "C:\Python34\lib\encodings\cp850.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2660' in position
4: character maps to <undefined>