ASCII字符扩展转换

5

如何使用Python将扩展ASCII字符(例如:"æ、ö 或 ç")转换为非扩展ASCII字符(a、o、c)?它的工作方式应该是,如果输入为"A、Æ、Ä",则返回所有字母的"A"。

1个回答

6

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'

看起来不错,但有没有办法在Python 2中实现这个?但如果没有的话,这个也可以。 - madprogramer
奇怪,我尝试了但没有成功。谢谢,我会使用Python 3的代码。 - madprogramer
8年后我可以说这个老化得很好 ;) - madprogramer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接