python中如何查看文件内容的编码方式

使用chardet查看文件文本内容的编码方式

代码:

import chardet

currentFile = open('dev_msra.bmes',mode='rb')
content = currentFile.read()

print(chardet.detect(content))

注意:open需要指定打开模式为'b'二进制打开,并且需要'rb'或'wb'或其他组合方式,仅使用'b'模式不够

猜你喜欢

转载自blog.csdn.net/weixin_41297561/article/details/108659846