简体   繁体   English

有没有办法从 Windows 在 python 终端中打印某些 unicode 字符?

[英]Is there a way to print certain unicode characters in python terminal from Windows?

So I have been trying to print in my terminal using Python the following Unicode characters:所以我一直在尝试使用 Python 在我的终端中打印以下 Unicode 个字符:


def printUnicode():
    print(u"\u2b1c")
    print(u"\u1f7e8")
    print(u"\u1f7e9")

However, this is my output: https://i.stack.imgur.com/pY9lc.png .但是,这是我的 output: https://i.stack.imgur.com/pY9lc.png

Even though I checked that I was using UTF-8 (chcp=65001), I do not why I cannot show those characters.即使我检查过我使用的是 UTF-8 (chcp=65001),我也不知道为什么我不能显示这些字符。 Idk if there is something wrong my PC configuration, the code or it just impossible to print them in windows cmd.如果我的 PC 配置、代码有问题或者无法在 windows cmd 中打印它们,我想知道。

Maybe you have wrong escape sequences in your string literals :也许您的字符串文字中有错误的转义序列:

import unicodedata   # access to the Unicode Character Database

def check_unicode(s):
    print(len(s), s)
    for char in s:
        print( char, '{:04x}'.format( ord(char)), 
               unicodedata.category( char),
               unicodedata.name( char, '(unknown)') )

Output : Output :

check_unicode( u"\u2b1c\u1f7e8\u1f7e9") # original string literals
 5 ⬜὾8὾9 ⬜ 2b1c So WHITE LARGE SQUARE ὾ 1f7e Cn (unknown) 8 0038 Nd DIGIT EIGHT ὾ 1f7e Cn (unknown) 9 0039 Nd DIGIT NINE
check_unicode( u"\u2b1c\U0001f7e8\U0001f7e9") # adjusted string literals
 3 ⬜ ⬜ 2b1c So WHITE LARGE SQUARE 1f7e8 So LARGE YELLOW SQUARE 1f7e9 So LARGE GREEN SQUARE

Edit.编辑。 Run in Windows Terminal using default Cascadia Code font…使用默认的Cascadia 代码字体在 Windows 终端中运行……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM