例如,在你的Python shell(IDLE)中:
>>> a = "\x3cdiv\x3e"
>>> print a
您得到的结果是:The result you get is:
<div>
但如果 a
是一个ASCII编码的字符串:
>>> a = "\\x3cdiv\\x3e" ## it's the actual \x3cdiv\x3e string if you read it from a file
>>> print a
你得到的结果是:
\x3cdiv\x3e
现在我真正想要的是一个 <div>
标签,所以我做了这个:
>>> b = a.decode("ascii")
>>> print b
但是令人惊讶的是,我没有得到我想要的结果,它仍然是:
\x3cdiv\x3e
所以基本上我要怎么将a
,也就是\x3cdiv\x3e
转换成b
,也就是应该是<div>
?
谢谢