I’m using Python 2.7
I’m reading a file containing “iso-8859-1” coded information.
After parsing, I get the results in strings, ie s1:
>>> s1
'D\xf6rfli'
>>> type(s1)
<type 'str'>
>>> s2=s1.decode("iso-8859-1").encode("utf8")
>>> s2
'D\xc3\xb6rfli'
>>> type(s2)
<type 'str'>
>>> print s1, s2
D�rfli Dörfli
>>>
Why is the type of s2 still a str after the call to .encode?
How can I convert it from str to utf-8?
I’m not sure if this answers your questions, but here’s what I observed.
If you just want to get the string into a printable form, just stop after calling decode. I’m not sure why you are trying to encode into UTF8 after successfully converting from is8859 into unicode.