【问题标题】:Unicode string to Unicode character, Python 3Unicode 字符串到 Unicode 字符,Python 3
【发布时间】:2024-12-19 04:00:02
【问题描述】:

我正在使用 Python 3.x 进行编程。假设我有以下 Unicode 字符串:

my_string =' \xed\x95\x9c'

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

【问题讨论】:

    标签: string python-3.x unicode utf-8


    【解决方案1】:

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

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

    Here is the code我曾经找到这个编码/解码链。

    【讨论】:

      最近更新 更多