读取编码为utf-16le的文件并打印

import codecs

data = open('test.txt').read()
if data[:2] == codecs.BOM_UTF16_LE:
    data = data[2:]
    print data.decode('utf-16le')

或者:
data = codecs.open('test.txt', 'r', 'utf-16le').read()

if data[0] == codecs.BOM_UTF16_LE.decode('utf-16le'):

    data = data[1:]
   
print data

你可能感兴趣的:(utf)