【问题标题】:remove unknown code in text using python使用python删除文本中的未知代码
【发布时间】:2014-11-08 17:26:06
【问题描述】:

我在文中看到\xe2\x80...之类的未知代码,这些代码到底是什么?以及如何从 python 中的文本中删除它们?

这是正文:

"Are you using bribery \xe2\x80\x94 or the less provocative \xe2\x80\x9crewards\xe2\x80\x9d \xe2\x80\x94 to push your girls to succeed this year?"

【问题讨论】:

  • 它们代表 UTF8 编码的字符。据我了解,您想打开一个文件,删除那些 UTF8 字符并保存文件?

标签: python html unicode


【解决方案1】:

您看到的未知代码是 和引号。所以这些是用 utf-8 编码的普通字符。如果你真的想删除它们:

text_without_unicode_chrs = ''.join(ch for ch in text if ch<'\x80')

【讨论】:

  • 看起来有点丑,为什么不text.decode("ascii", errors="ignore")
猜你喜欢
  • 2012-08-22
  • 2015-08-14
  • 2021-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-25
  • 1970-01-01
相关资源
最近更新 更多