Skip to main content
 首页 » 编程设计

python之如何将带有斯堪的纳维亚字符的 UTF 字符串转换为 ASCII

2025年05月04日18yxwkf

我想转换这个字符串

foo_utf = u'nästy chäräctörs with å and co.' # unicode 

进入这个

foo_ascii = 'nästy chäräctörs with å and co.' # ASCII 

.

知道如何在 Python (2.6) 中执行此操作吗?我找到了 unicodedata模块,但我不知道如何进行转换。

请您参考如下方法:

我认为你做不到。那些“nästy chäräctörs”无法编码为 ASCII,因此您必须选择不同的编码(UTF-8 或 Latin-1 或 Windows-1252 或其他编码)。