myTestFreqAI/utf8.py
zhangkun9038@dingtalk.com cca246abfd log ok
2025-04-29 10:22:02 +08:00

19 lines
697 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import chardet
import codecs
def convert_encoding(input_file, output_file):
# 检测文件编码
with open(input_file, 'rb') as f:
result = chardet.detect(f.read())
encoding = result['encoding']
# 以检测到的编码读取文件内容并以UTF-8编码写入新文件
with codecs.open(input_file, 'r', encoding=encoding) as infile, \
codecs.open(output_file, 'w', encoding='utf-8') as outfile:
outfile.write(infile.read())
if __name__ == "__main__":
input_file = 'freqtrade.log' # 替换为实际的输入文件名
output_file = 'freqtrade_utf8.log' # 替换为你想要的输出文件名
convert_encoding(input_file, output_file)