[英]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.
Unicode似乎是最好的方法。
I am using Eclipse for IDE developers coupled with a pydev module. 我正在将Eclipse用于IDE开发人员以及pydev模块。 It's running Python 3.0.
它正在运行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? 我错过了什么?
Don't encode; 不要编码; the
sys.stdout
file stream is opened with your terminal encoding and encodes unicode for you: 使用终端编码打开
sys.stdout
文件流并为您编码unicode:
club = u"\u2663"
print(club)
You don't need to use u''
; 你不需要使用
u''
; python 3 strings are unicode values by default . python 3字符串默认为unicode值。
Demo: 演示:
>>> club = "\u2663"
>>> print(club)
♣
That you shouldn't need to encode. 你不应该编码。
3>> print('\u2663')
♣
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.