I am converting some code from python2 to python3.
In python2, I can do the following things:
>>> c = '\xe5\xb8\x90\xe6\x88\xb7'
>>> print c
帐户
>>> c.decode('utf8')
u'\u5e10\u6237'
How can I get that same output (u'\u5e10\u6237') in python3?
Edit
For anyone else with this problem, I realized after looking at the the responses that to make use of the result each character needs to be treated as an individual element. An escaped unicode representation like '\u5e10\u6237' is a string so it would not naturally divide into parts that correspond to the original chinese characters.
>>> c = '帐户'
>>> type(c.encode('unicode-escape').decode('ascii'))
<class 'str'>
>>> [l for l in c.encode('unicode-escape').decode('ascii')]
['\\', 'u', '5', 'e', '1', '0', '\\', 'u', '6', '2', '3', '7']
You have to separate each character in the input string and translate it separately into an array unless you want to parse it again in the next part of your program. My solution was thus:
>>> [l.encode('unicode-escape').decode('ascii') for l in c]
['\\u5e10', '\\u6237']
An alternate solution make each character into a hex representation:
>>> [hex(ord(l)) for l in c]
['0x5e10', '0x6237']
Thanks for the help.