0

It seems to me as if python print can't print German umlauts in lists, dictionary and tuples. How can I change this?

# -*- coding: cp1252 -*-
print 'ÄÖÜ' #'ÄÖÜ'

x = 'ÄÖÜ'
print x #'ÄÖÜ'

x = ['ÄÖÜ',]
print x #['\xc4\xd6\xdc']
print x[0] #'ÄÖÜ'

x = [u'ÄÖÜ',]
print x #['\xc4\xd6\xdc']
print x[0] #'ÄÖÜ'

x = {'Ä': 'Ü'}
print x #{'\xc4': '\xdc'}
print x['Ä'] #'Ü'
glibdud
  • 7,131
  • 2
  • 23
  • 34
am2
  • 385
  • 5
  • 17
  • 1
    Switch to python 3!! ;) – Nordle Mar 20 '19 at 12:14
  • I can't in this moment, no way in 2.7? – am2 Mar 20 '19 at 12:47
  • try using unicode ? https://stackoverflow.com/questions/22745876/python-print-unicode-list – Julien Mar 20 '19 at 12:50
  • 1
    Possible duplicate of [Why do I get the u"xyz" format when I print a list of unicode strings in Python?](https://stackoverflow.com/questions/2180929/why-do-i-get-the-uxyz-format-when-i-print-a-list-of-unicode-strings-in-python) – tripleee Mar 20 '19 at 12:53

1 Answers1

-2

Change your coding to this:

# -*- coding: cp852 -*-
StitZle
  • 81
  • 2
  • 11
  • 1
    This won't help. The `coding` hint tells the Python interpreter what encoding your source code file (*.py) is saved as, it will not do anything about the output. And the fact that it displays `'ÄÖÜ'` when printing a string means that the source code encoding already is correct. – Tomalak Mar 20 '19 at 12:36