蟒蛇 - 文件被加载了错误的编码UTF-8

问题描述:

即时通讯相当新的编程,我不明白这个错误消息我得到,file was loaded in the wrong encoding utf-8或它不是真的在代码中的错误消息,但我得到它我的新的.txt文件,我写所有找到的关键字。 .txt文件将upp更改为4000多行,并将信息排序到另一个程序的Excel中,然后将其发送到Access。信息意味着什么,并且有办法解决它?使用pycharm与anaconda36蟒蛇 - 文件被加载了错误的编码UTF-8

enter image description here

import glob 


def LogFile(filename, tester): 

    data = [] 
    with open(filename) as filesearch: # open search file 
     filesearch = filesearch.readlines() # read file 
    file = filename[37:] 
    for line in filesearch: 
     if tester in line: # extract "Create Time" 
      short = line[30:] 
      data.append(short) # store all found wors in array 

    print (file) 

    with open('Msg.txt', 'a') as handler: # create .txt file 

     for i in range(len(data)): 
      handler.write(f"{file}|{data[i]}") 


# open with 'w' to "reset" the file. 
with open('LogFile.txt', 'w') as file_handler: 
    pass 
# --------------------------------------------------------------------------------- 

for filename in glob.glob(r'C:\Users\Documents\Access\\GTX797\*.log'): 
    LogFile(filename, 'Sending Request: Tester') 
+0

你在用什么IDE? –

+1

如果您要提出有关您在文本编辑器中看到的消息的问题,请告诉我们您正在使用哪种文本编辑器。 –

+0

@AzatIbrakov即时通讯使用pycharm与anaconda – fili

感谢

IM我只是有同样的错误在pyCharm和创建文件时指定UTF-8固定它。您将需要导入编解码器来执行此操作。

import codecs 

with codecs.open(‘name.txt', 'a', 'utf-8-sig') as f: