网络编程
位置:首页>> 网络编程>> Python编程>> python自动识别文本编码格式代码

python自动识别文本编码格式代码

作者:qq_34500270  发布时间:2024-01-02 06:29:50 

标签:python,自动识别,编码格式

我就废话不多说了,直接上代码吧!


#!/usr/bin/python3
# -*- coding: utf-8 -*-
import codecs
import os
import chardet

def detectCode(path):
with open(path, 'rb') as file:
data = file.read(200000)
dicts = chardet.detect(data)
return dicts["encoding"]

# 文件所在目录
if __name__ == '__main__':
path = input("输入log文件路径: ")
print(detectCode(path))

来源:https://blog.csdn.net/qq_34500270/article/details/82900297

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com