python : working with german umlaut

deimus picture deimus · Aug 31, 2011 · Viewed 47.9k times · Source
months = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"]

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

Printing month[2] fails with

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

help to get rid of this!

Answer

Cédric Julien picture Cédric Julien · Aug 31, 2011

Did you add an encoding in the begining of your source file ?

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