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
Post a Comment