清理特殊文本

  • unicodedata.normalize(form, unistr)

把一串UNICODE字符串转换为普通格式的字符串,具体格式支持NFC、NFKC、NFD和NFKD格式。

Unicode标准定义了四种规范化形式: Normalization Form D (NFD),Normalization Form KD (NFKD),Normalization Form C (NFC),和Normalization Form KC (NFKC)。大约来说,NFD和NFKD将可能的字符进行分解,而NFC和NFKC将可能的字符进行组合。

import unicodedata
a = 'pýtĥöñ is awesome\n'
b = unicodedata.normalize('NFD',a)
b.encode('ascii', 'ignore').decode('ascii')

相关文章:

  • 2021-12-22
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2021-12-26
  • 2021-05-16
  • 2021-11-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
  • 2021-10-11
  • 2022-01-14
相关资源
相似解决方案