1. 程式人生 > >python自動識別文字編碼格式

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))