python : working with german umlaut

标签 python unicode diacritics

months = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]

print months[2].decode("utf-8")

打印月 [2] 失败并显示

UnicodeDecodeError: 'utf8' codec can't decode bytes in position 1-2: invalid data

帮助摆脱这个!

最佳答案

您是否在源文件的开头添加了编码?

# -*- coding: utf-8 -*-

关于 python : working with german umlaut,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7254047/

相关文章:

python - 从文件读取时一次性跳过所有空间

Python 命名空间和 import : setting the value of a global variable in an imported module creates a second, 无关全局?

python - 如何在 Python 级别将 unicode 转换为字符串?

unicode - 使用 US 布局在 Emacs 中快速输入 unicode

javascript - 单击 div 后将焦点返回到输入字段

java - 将 ä、ö、ü 重命名为 ae、oe、ue

java - Eclipse 中的 Jython 项目找不到 xml 模块,但在相同的项目中工作

python - 使用另一个数据帧同一列中的值更新数据帧中的列

python - python中字符串前的 'u'是什么意思?

ios - URL AFNetworking GET 中的变音符号