【问题标题】:text with unicode escape sequences to unicode in python [duplicate]带有unicode转义序列的文本到python中的unicode [重复]
【发布时间】:2011-04-29 14:23:26
【问题描述】:

可能重复:
Conversion of strings like \\uXXXX in python

嗨,假设我有字符串

test
'\\u0259'

注意转义的反斜杠。

如何将其转换为相应的 unicode 字符串?

【问题讨论】:

    标签: python unicode


    【解决方案1】:
    >>> print('test \\u0259'.decode('unicode-escape'))
    test ə
    

    【讨论】:

    • +1。请注意,如果您运行 python 3.x,则需要 print(bytes('test \\u0259', 'ascii').decode('unicode-escape'))
    • 如何在没有print的情况下获得符号ə
    • bytes('test \\u0259', 'ascii') == b'test \\u0259'
    • 如果我们需要将文本存储在 json 文件中怎么办
    • @FrédéricHamidi 您在 2010 年的回答让我的大脑免于在 2021 年在这里融化。传奇。所以说避免“+1”的东西,但这值得特别提及。
    猜你喜欢
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 2019-06-16
    • 2021-01-30
    • 1970-01-01
    • 2014-08-15
    • 1970-01-01
    相关资源
    最近更新 更多