python - 从 Python 中的 unicode 字符串替换非 ascii 字符

标签 python ascii

如何在 Python 中替换 unicode 字符串中的非 ascii 字符?

这是我对给定输入的输出:

音乐 -> 音乐

纸箱 -> 纸箱

卡诺 -> 卡诺

Myaybe 有一个字典,其中 'á' 是键,'a' 是值?

最佳答案

如果您只想将重音字符降级为非重音字符:

>>> import unicodedata
>>> unicodedata.normalize('NFKD', u"m\u00fasica").encode('ascii', 'ignore')
'musica'

关于python - 从 Python 中的 unicode 字符串替换非 ascii 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3704731/

相关文章:

python - 将两个数组相乘得到矩阵

python - scikit-learn 的 LabelEncoder() 内存问题

python - Windows 操作系统上 Python 和 Win32 之间的 IPC

python - 如何在 Windows 上安装 scipy 包?

dart - 如何将整数中的ascii值转换为 flutter 中的等效字符?

c++ - 从 ASCII 到 Unicode 字符代码的转换 (FreeType2)

Java - 在不使用 toUppercase() 的情况下将小写字母转换为大写字母

c# - Windows键的ascii码是什么?

python - 如何在主管中激活python虚拟环境?

java - 将十六进制转换为特殊字符 (Java)