Piotr
Piotr

Reputation: 39

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?

Upvotes: 1

Views: 2473

Answers (1)

Stop harming Monica
Stop harming Monica

Reputation: 12590

The escape sequence \u 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.

Upvotes: 2

Related Questions