Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 html 文件中,我有包含软连字符的单词,例如
"Schilde rung" repr(word) = "Schilde\\xc2\\xadrung"
我怎样才能删除它们?
由于我的文件还包含变音符号和其他特殊字符,因此具有可打印或具有可打印的解决方案words.decode('ascii', 'ignore')并不是非常好......
words.decode('ascii', 'ignore')
我已经尝试过使用words.replace('\xc2\xad', ''); 但这没有用。
words.replace('\xc2\xad', '')
谢谢你的帮助 :)
您不能replace在列表上运行;您需要在列表的每个成员上运行它:
replace
words = ["Hello", "Schilde\xc2\xadrung"] words = [word.replace('\xc2\xad', '') for word in words] print repr(words) # Prints ['Hello', 'Schilderung']