2017-06-16 232 views
1

我使用Python 3.x进行编程。说我有以下Unicode字符串:Unicode字符串为Unicode字符,Python 3

my_string =' \xed\x95\x9c'

'\xed\x95\x9c'实际上是韩语字符的UTF-8字节流。将my_string转换为的最简单方法是什么? my_string.decode('utf-8')不起作用,因为my_string是一个Unicode字符串,而不是字节字符串。

回答

2

有很多可能的encode/decode链,导致所需的结果。这里是一个:

In [257]: '\xed\x95\x9c'.encode('latin-1').decode('utf-8') 
Out[257]: '한' 

Here is the code我以前找到这个编码/解码链。