安装:
pip install chardet
代码:
import chardetfilePath = r"C:\Users\Lenovo\Desktop\G0001.TextGrid"with open(filePath, "rb") as f:content = f.read()result = chardet.detect(content)print(result)
结果:
{'encoding': 'UTF-16', 'confidence': 1.0, 'language': ''}其中 **confidence** 是检测后的可信度, **encoding** 是编码格式