python 读取行去除换行符
f = open('filepath','r')
data = [line.strip('\n') for line in f.readlines()]
读取文件的编码格式
pip install chardet
import chardet
your_path = './log.txt'
def check_charset(file_path):
with open(file_path, "rb") as f:
data = f.read(4)
charset = chardet.detect(data)['encoding']
return charset
print(check_charset(your_path))