chardet 是第三方模块,需要下载安装
官方地址: http://pypi.python.org/pypi/chardet
# 首先二进制方式打开文件
with open(absPath, 'rb') as frb:
# 检测编码方式
cur_encoding = chardet.detect(frb.read())['encoding']
# 指定文件编码方式
with open(absPath, 'r', encoding=cur_encoding) as fr:
Content = fr.read()