1

在 html 文件中,我有包含软连字符的单词,例如

"Schilde rung"
repr(word) = "Schilde\\xc2\\xadrung"

我怎样才能删除它们?

由于我的文件还包含变音符号和其他特殊字符,因此具有可打印或具有可打印的解决方案words.decode('ascii', 'ignore')并不是非常好......

我已经尝试过使用words.replace('\xc2\xad', ''); 但这没有用。

谢谢你的帮助 :)

4

1 回答 1

4

您不能replace在列表上运行;您需要在列表的每个成员上运行它:

words = ["Hello", "Schilde\xc2\xadrung"]
words = [word.replace('\xc2\xad', '') for word in words]
print repr(words)
# Prints ['Hello', 'Schilderung']
于 2013-09-06T21:21:51.033 回答