python : working with german umlaut

前端 未结 2 1660
情歌与酒
情歌与酒 2020-12-10 02:34
months = [\"Januar\", \"Februar\", \"März\", \"April\", \"Mai\", \"Juni\", \"Juli\", \"August\", \"September\", \"Oktober\", \"November\", \"Dezember\"]

print month         


        
相关标签:
2条回答
  • 2020-12-10 02:53

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

    # -*- coding: utf-8 -*-
    
    0 讨论(0)
  • 2020-12-10 02:56

    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.

    0 讨论(0)
提交回复
热议问题