我正在尝试学习 python,但不知道如何将以下 perl 脚本翻译成 python:
#!/usr/bin/perl -w
use open qw(:std :utf8);
while(<>) {
s/\x{00E4}/ae/;
s/\x{00F6}/oe/;
s/\x{00FC}/ue/;
print;
}
脚本只是将 unicode 变音符号更改为替代 ascii 输出。 (所以完整的输出在 ascii 中。)我将不胜感激任何提示。谢谢!
最佳答案
要转换为 ASCII,您可能需要尝试 ASCII, Dammit或 this recipe ,归结为:
>>> title = u"Klüft skräms inför på fédéral électoral große"
>>> import unicodedata
>>> unicodedata.normalize('NFKD', title).encode('ascii','ignore')
'Kluft skrams infor pa federal electoral groe'
关于python - 如何在 Python 中用 ascii 字符替换 unicode 字符(给定的 perl 脚本)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2700859/