[英]How do I treat an ASCII string as unicode and unescape the escaped characters in it in python?
[英]How do I unescape a unicode escaped string in python?
我有一个unicode转义字符串:
> str = 'blah\\x2Ddude'
我想将此字符串转换为unicode非转义版本'blah-dude'
我该怎么做呢?
将其编码为bytes
(使用任何编解码器,utf-8可能有效)然后使用unicode-escape
解码它:
s = 'blah\\x2Ddude'
s.encode().decode('unicode-escape')
Out[133]: 'blah-dude'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.