【问题标题】:Unicode string to Unicode character, Python 3Unicode 字符串到 Unicode 字符,Python 3
【发布时间】:2017-11-19 19:44:40
【问题描述】:

我正在使用 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我曾经找到这个编码/解码链。

    【讨论】:

      猜你喜欢
      • 2011-11-12
      • 2021-11-03
      • 2017-03-15
      • 1970-01-01
      • 2018-04-29
      • 2011-11-07
      • 2012-05-03
      • 2012-04-21
      相关资源
      最近更新 更多