David542
David542

Reputation: 110153

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?

Upvotes: 3

Views: 1971

Answers (1)

Tim Pietzcker
Tim Pietzcker

Reputation: 336138

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")

Upvotes: 6

Related Questions