简体   繁体   中英

Displaying extended Unicode characters in Python curses

I'm writing a game using the curses library. I am trying to display some non-standard Unicode characters, and there I encountered a problem.

Let's say I want to display an Unicode tree character. Quick google renders something like this:

“🌲” (U+1F332)

However, when I try to display that in my Python terminal, CMD or using curses a curses window, all I get is this:

In: u'\u1F332'
Out: 'ἳ2' 

Is that because the font I am using doesn't support this particular character? Is there a way of adding additional Unicode characters to the curses library?

The escape sequence \\u\u003c/code> interprets the following four characters (in your case 1F33 ) as a 16 bits hexadecimal expression, which is not what you want. Since your code point does not fit in 16 bits you need the escape sequence \\U and provide a 32 bits (eight characters long) hexadecimal expression.

In [1]: '\U0001F332'                                                            
Out[1]: '🌲'

(I am guessing from your output that you are using python 3.)

You might also have issues with your terminal encoding and font, but your current code doesn't let you even get to that point.

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