#获取文件的编码字符格式import chardetdef func(file): with open(file,"rb") as f: return chardet.detect(f.read())print(func("C:\\Users\\l\\Desktop\\error.txt"))