如何使用Python将扩展ASCII字符(例如:"æ、ö 或 ç")转换为非扩展ASCII字符(a、o、c)?它的工作方式应该是,如果输入为"A、Æ、Ä",则返回所有字母的"A"。
如何使用Python将扩展ASCII字符(例如:"æ、ö 或 ç")转换为非扩展ASCII字符(a、o、c)?它的工作方式应该是,如果输入为"A、Æ、Ä",则返回所有字母的"A"。
Unidecode可能对您有用。
Python 3.2.3 (default, Jun 8 2012, 05:36:09)
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from unidecode import unidecode
>>> unidecode("æ, ö or ç")
'ae, o or c'