简体   繁体   中英

Displaying unicode characters in Python 3

I have issues with displaying Unicode characters. As an output I have this list (only on online IDEs):

[u'\u0413', u'\0434', u'\043b']

How can I convert this sequence to normally visible text? I have # -*- coding: utf-8 -*- in header and also each string marked as Unicode like u'String'

I tried to use code: myList = repr([x.encode(sys.stdout.encoding) for x in lst]).decode('string-escape') but it's not working and output still the same.

In Python 3, this will work directly:

>>> [u'\u0413', u'\0434', u'\043b']
['Г', '#4', '#b']

In Python 2, you can use the print statement to print individual values:

>>> for val in [u'\u0413', u'\0434', u'\043b']:
...   print val
... 
Г
#4
#b

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