Python和字符规范化 [英] Python and character normalization
本文介绍了Python和字符规范化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello
从外部来源检索基于文本的utf8数据,其中包含特殊字符,例如 uıöüç
,而我想将其标准化为英文作为ıöüç
- > iouc
。实现这个的最好方法是什么?
Hello
I retrieve text based utf8 data from a foreign source which contains special chars such as u"ıöüç"
while I want to normalize them to English such as "ıöüç"
-> "iouc"
. What would be the best way to achieve this ?
推荐答案
我建议使用 Unidecode模块:
>>> from unidecode import unidecode
>>> unidecode(u'ıöüç')
'iouc'
注意你如何喂它一个unicode字符串,并输出一个字节串。输出保证是ASCII。
Note how you feed it a unicode string and it outputs a byte string. The output is guaranteed to be ASCII.
这篇关于Python和字符规范化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文