Python自动将德语元音和标点符号读取为
Gefrier- undçhlmçbel
如何规范化此输出以删除标点符号?
发布于 2020-10-16 20:07:20
您可以通过执行以下操作来“修复”编码问题:
the_string = 'Gefrier- und Tiefkühlmöbel'.encode('latin-1').decode('utf-8')然后应用像这样的解决方案:https://stackoverflow.com/a/518232/2452074
import unicodedata
def strip_accents(s):
return ''.join(c for c in unicodedata.normalize('NFD', s)
if unicodedata.category(c) != 'Mn')
strip_accents(the_string)
> 'Gefrier- und Tiefkuhlmobel'但是首先,我会试着理解为什么你的输入看起来是错误的,Python本身不应该自动地这样做。
关于unicode和编码的一些背景文档:https://docs.python.org/3/howto/unicode.html
https://stackoverflow.com/questions/64388028
复制相似问题