user2477853
user2477853

Reputation: 21

How can I output Unicode symbols in Python 3.0?

I am working on a little euchre project for those of you who are familiar with that. I need suit symbols to identify the cards in my game. Unicode seems to be the best way of doing that.

I am using Eclipse for IDE developers coupled with a pydev module. It's running Python 3.0.

It should just be as simple as:

club = u"\u2663".encode('utf-8')
print(club)

My output is literally:

>>> b'\xe2\x99\xa3'

What am I missing?

Upvotes: 2

Views: 1834

Answers (2)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799310

That you shouldn't need to encode.

3>> print('\u2663')
♣

Upvotes: 5

Martijn Pieters
Martijn Pieters

Reputation: 1124558

Don't encode; the sys.stdout file stream is opened with your terminal encoding and encodes unicode for you:

club = u"\u2663"
print(club)

You don't need to use u''; python 3 strings are unicode values by default.

Demo:

>>> club = "\u2663"
>>> print(club)
♣

Upvotes: 7

Related Questions