How to view the encoding of file content in python

Use chardet to view the encoding of the text content of the file

Code:

import chardet

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

print(chardet.detect(content))

Note: Open needs to specify the open mode as'b' binary open, and it needs'rb' or'wb' or other combination methods, only using the'b' mode is not enough

Guess you like

Origin blog.csdn.net/weixin_41297561/article/details/108659846