[英]How to decode a unicode-like string in Python 3?
I have unicode-like strings but with slash escaped. 我有类似unicode的字符串,但有斜线转义。 For example, '\\\ '
. 例如, '\\\ '
。 I need to decode them as normal strings. 我需要将它们解码为普通字符串。 The above example should be convert to '\\r'
which '\ '
corresponds to. 上面的例子应该被转换为'\\r'
其中'\ '
对应。
Use the unicode-escape
codec. 使用unicode-escape
编解码器。
>>> import codecs
>>> codecs.decode('\\u000D', 'unicode-escape')
'\r'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.