简体   繁体   中英

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:


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

However, this is my 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. Idk if there is something wrong my PC configuration, the code or it just impossible to print them in 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 :

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…

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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