17
votes
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!

2
works perfectly in my python2 interpreter. Most likely a coding fail of the file, did you add # -*- coding: utf-8 -*- at the top of the file? - naeg

2 Answers

37
votes

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

# -*- coding: utf-8 -*-
5
votes

Are you sure you are working in UTF8?

Nevertheless, I would recommend to define

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

print months[2]

and if you do some stuff basing on bytes, you encode() the data into the charset you need.