I'm studying python(2.7) scrapy. I try to read a file which is utf-16-le encoded, each line of the file is unicode string, but it contains ascii characters.
str1 = u'Asus,\xe9\xa3\x9e\xe9\xa9\xac'
print type(str1), str1
# print 'decoding', str1.decode('utf-8') # it throws UnicodeEncodeError
str2 = 'Asus,\xe9\xa3\x9e\xe9\xa9\xac'
print type(str2), str2
print 'decoding', str2.decode('utf-8')
The output of console is:
<type 'unicode'> Asus,é£é©¬
<type 'str'> Asus,飞马
decoding Asus,飞马
How can i convert str1 to 'Asus,飞马' liked unicode string, all answer will be appreciated.