character encoding - Python: Converting from ISO-8859-1/latin1 to UTF-8 -


i have string has been decoded quoted-printable iso-8859-1 email module. gives me strings "\xc4pple" correspond "Äpple" (apple in swedish). however, can't convert strings utf-8.

>>> apple = "\xc4pple" >>> apple '\xc4pple' >>> apple.encode("utf-8") traceback (most recent call last):   file "<stdin>", line 1, in <module> unicodedecodeerror: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in     range(128) 

what should do?

try decoding first, encoding:

apple.decode('iso-8859-1').encode('utf8') 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -