Unicode in the dictionary gives hexadecimal output

I have a couple of words (key, meaning). The key is "ASCII" (for example, "hello"), the value is not English (for example, Chinese ่ผธๅ…ฅ ๆ›ฒ็›ฎ).

Some codes:

t_t = {} s_0 = 'hello' s_v = '่ผธๅ…ฅๆ›ฒ็›ฎ' print s_v # gives the Chinese ่ผธๅ…ฅๆ›ฒ็›ฎ t_t[s_0] = s_v print t_t.values() 

Hexadecimal output (e.g. '\ x39 \ xef')

Even access to the value in the code:

 ss = t_t['hello'] print ss 

gives me hex.

Since I use this as a translator, I really need Unicode.

Running this through the DOS console window on Windows 7. Python version - 2.7.1

+4
source share
1 answer

You will need to maintain the values โ€‹โ€‹manually. The fingerprint turns it into hex because you ask it to print the entire tuple and the print will see your string as arbitrary binary data. In order to not completely spoil some user terminals, it encodes potentially non-printable characters as hex. The content of the line is not affected - it is just a product of how you display it.

As an example:

 for v in t_t.values(): print v 

This should print the expected values.

You should also consider using Python 3 or Unicode strings (u "Unicode string"). Now you do not have a portable device and it depends on your system encoding.

+7
source

All Articles