我有一个 Unicode 转义字符串:
> str = 'blah\\x2Ddude'
我想将这个字符串转换为未转义的Unicode版本:'blah-dude'
我该怎么做?
我有一个 Unicode 转义字符串:
> str = 'blah\\x2Ddude'
我想将这个字符串转换为未转义的Unicode版本:'blah-dude'
我该怎么做?
将其编码为bytes
(使用任何编解码器,通常utf-8可以)然后使用unicode-escape
进行解码:
s = 'blah\\x2Ddude'
s.encode().decode('unicode-escape')
Out[133]: 'blah-dude'
encode
函数。你只需要 import codecs
然后调用 codecs.decode(s, 'unicode-escape')
即可。 - Mark H
import html; html.escape('this <is> &escaped&')
和html.unescape('this <is> &escaped&')
- jfs'\\x2d'
和'\x2d'
之间的区别吗? - jfs