Python code
for line in open(path, 'rb').read().decode('UTF-16LE').split('\n'):
print line
[/Quote]
哈哈 可以了,我刚学这个以前没学过编程的,门外汉,呵呵,非常感谢!!4楼是我在你三楼没回复前回复的,不好意思
另外注意下换行问题。如果换行符也是utf-16le的,readlines可能有问题。直接print f.read().decode('utf-16')。兴许open的时候还要加'rb'。如果没问题的话就算了。
[/Quote]
我需要一行一样打印
f=open(file)
for i in f.readlines():
print i.decode('utf-16')
raceback (most recent call last):
File "F:\testmodule.py", line 26, in <module>
print i.decode('utf-16')
File "C:\Python27\lib\encodings\utf_16.py", line 16, in decode
return codecs.utf_16_decode(input, errors, True)
UnicodeDecodeError: 'utf16' codec can't decode byte 0x0a in position 182: truncated data
>>>