我的文字如下:
"\x91It will have to be paid for,\x92 they said. \x91It isn\x92t natural, and\ntrouble will come of it!"
我想将其转换为:
"'It will have to be paid for,' they said. 'It isn't natural, and\ntrouble will come of it!"
答案 0 :(得分:0)
data = r"\x91It will have to be paid for,\x92 they said. \x91It isn\x92t natural, and\ntrouble will come of it!"
print data.replace('\\x91',"'").replace('\\x92',"'")
答案 1 :(得分:0)
\x91
表示LEFT SINGLE QUOTATION MARK
,\x92
表示代码页1252中的RIGHT SINGLE QUOTATION MARK
。
您可以通过以下方式获取原始文本:
text = "\x91It will have to be paid for,\x92 they said. \x91It isn\x92t natural, and\ntrouble will come of it!"
print unicode(text, 'cp1252')
答案 2 :(得分:0)
>>> unidecode.unidecode("\x91It will have to be paid for,\x92 they said. \x91It isn\x92t natural, and\ntrouble will come of it!".decode('cp1252'))
"'It will have to be paid for,' they said. 'It isn't natural, and\ntrouble will come of it!"