# 修复文件开头的BOM字符 import os # 文件路径 file_path = 'd:\\code\\PriceForecast-svn\\main_juxiting.py' # 读取文件(二进制模式) with open(file_path, 'rb') as f: content = f.read() # 检查并移除BOM字符(EF BB BF是UTF-8 BOM的字节序列) if content.startswith(b'\xef\xbb\xbf'): content = content[3:] # 写回文件 with open(file_path, 'wb') as f: f.write(content) print('BOM has been removed successfully!') else: print('No BOM found in the file.')