I have a question about unicodes and the string formatting % in python. I have the following four cases:
case:
# -*- encoding: utf -*- print '%s' % 'München'case:
# -*- encoding: utf -*- print '%s' % u'München'case:
# -*- encoding: utf -*- print u'%s' % u'München'case:
# -*- encoding: utf -*- print u'%s' % 'München'
Cases 1-3 work fine but in case 4 I get the error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)
So my questions are: why do the cases 1-3 work (especially case 2) and why does case 4 fail?
I know how to fix my problem but I want to understand why this problem happens, so I would be happy if someone could help me. Thanks!
PS: Thanks for the links to possible duplicates but sadly my problems aren't solved by Why does Python 2.x throw an exception with string formatting + unicode? because in this they don't use a unicode for the to-be-formated-string. So they do cases 1 and 2 but not 4, and especially case 2 does work for me and breaks for them...