How can I concatenate a string and a Unicode and get a string as a result? I tried the following. But this is obviously not correct.
>>> s = 'jklö'
>>> u = u'äpoi'
>>> print s+u
Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position 3: ordinal not in range(128)
>>> unicode(s, 'latin-1')+u
u'jkl\x94\xe4poi'
>>> (unicode(s, 'latin1')+u).encode('latin1')
'jkl\x94\xe4poi'
>>> print (unicode(s, 'latin1')+u).encode('latin1')
jklöõpoi
sexplicitly (usingunicode()), so it can append the results. That's the correct way to concatenate unicode data; by using only unicode objects. - Martijn Pieters