确定文件的字符编码模式
=============================================================================
# 如果你不确定log文件的具体编码,你可以尝试使用Python的chardet库来自动检测文件的字符编码。你可以使用以下代码:
=============================================================================
import chardet
file_path = "path/to/your/log/file.log"
with open(file_path, "rb") as file:
raw_data = file.read()
result = chardet.detect(raw_data)
encoding = result["encoding"]
print("Detected Encoding:", encoding)
content = raw_data.decode(encoding)
print(content)