import chardet f = open(file='test1.txt', mode='rb') data = f.read() print(chardet.detect(data)) 转载于:https://www.cnblogs.com/wt7018/p/11064565.html