Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kanji characters in utf-8

>>> s='未作評級'
>>> s
'\xe6\x9c\xaa\xe4\xbd\x9c\xe8\xa9\x95\xe7\xb4\x9a'
>>> s = unicode(s)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 0: ordinal not in range(128)

How would I get the 未作評級 into uniciode?

like image 328
David542 Avatar asked Nov 18 '25 18:11

David542


1 Answers

Either use a Unicode string from the start:

>>> s = u'未作評級'

or decode the string from its current encoding (which appears to be UTF-8). Then you get a Unicode string.

>>> s = '未作評級'.decode("utf-8")
like image 102
Tim Pietzcker Avatar answered Nov 21 '25 08:11

Tim Pietzcker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!