[英]German Umlaute in CSV as literals
I have a csv that contains a field with German Umlaute (ä,ö,ü) as literals such like this: 我有一个csv,其中包含一个带有德国Umlaute(ä,ö,ü)字段的文字,如下所示:
b'Beitr\\xc3\\xa4ge'
I've tried to read this .csv and just print the original words ( Beiträge
), but no matter what I do, I only seem to get b'Beitr\\xc3\\xa4ge'
back. 我尝试阅读此.csv并仅打印原始单词( Beiträge
),但是无论我做什么,我似乎只回来了b'Beitr\\xc3\\xa4ge'
。 I've tried following all sorts of advice on how to convert to and from Unicode, I've tried both Python 2.7 and 3, but I'm stumped. 我已经尝试过各种关于如何与Unicode相互转换的建议,我已经尝试了Python 2.7和3,但是我很困惑。
What should I do? 我该怎么办?
Use the decode funtion: 使用解码功能:
b'Beitr\xc3\xa4ge'.decode('utf-8')
returns 回报
Beiträge
I have to use these "Umlaute" as well. 我也必须使用这些“ Umlaute”。 To solve that problem I write in every first line of my python modules 为了解决这个问题,我在python模块的每一行中编写了代码
# -*- coding: iso-8859-1 -*-
Works fine for me in Python 3.6 If I than type s.th. 如果我不输入s.th,则在Python 3.6中对我来说效果很好。 like 喜欢
print("Beträge")
The output in the console is "Beträge" 控制台中的输出为“Beträge”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.