問題描述
我想知道是否可以在 Windows 上的 Python 3 控制臺中打印表情符號.實際上,為了避免以下錯誤:
I wonder if it's possible to print Emojis in a Python 3 console on Windows. Actually, to avoid the following error:
codec can't encode character 'U0001f44d' in position 10: character maps to
<undefined>
我用過:
import emoji as moji
print(moji.emojize('Python is :thumbsup:', use_aliases=True).encode('unicode-
escape'))
也就是說,如預期的那樣,打印正確的character:U0001f44d
,沒有任何exception
.
which is, as expected, printing the right character:U0001f44d
without any exception
.
推薦答案
Windows 命令提示符對于 Unicode 字符有很多限制,尤其是那些基本多語言平面之外的字符(BMP,或 U+0000 到 U+FFFF).命令提示符默認為舊版 OEM 編碼(美國 Windows 上為 cp437),并且對本地化編碼之外的字符的字體支持有限.尋找一個對 UTF-8 有良好支持的 Python IDE.
The Windows command prompt has a lot of limitations with regards to Unicode characters, especially those outside the basic multilingual plane(BMP, or U+0000 to U+FFFF). The command prompt defaults to a legacy OEM encoding (cp437 on US Windows) and has limited font support for characters outside the localized encoding. Find a Python IDE that has good support for UTF-8.
查看各種 Unicode 字符的一種快速而簡單的方法是寫入文件并利用瀏覽器:
One quick-and-dirty way to see a wide variety of Unicode characters is to write to a file and leverage the browser:
import os
with open('test.htm','w',encoding='utf-8-sig') as f:
f.write('U0001f44d')
os.startfile('test.htm')
這顯示 在我的 Windows 10 系統上的最新 Chrome 瀏覽器中.
This displays in the latest Chrome browser on my Windows 10 system.
這篇關于在 Python 的控制臺中顯示 Emoji的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!