我在学习python(2.7)scrapy。 我试图读取一个utf-16-le编码的文件,文件的每一行都是unicode字符串,但它包含ascii字符。在
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')
控制台的输出为:
^{pr2}$我如何将str1转换成“Asus,飞马”喜欢的unicode字符串,所有答案将不胜感激。在
我想知道你是怎么操纵的。以下是我的工作
相关问题 更多 >
编程相关推荐