2017-06-21 115 views
0

即時通訊相當新的編程,我不明白這個錯誤消息我得到,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

回答

0

感謝

IM我只是有同樣的錯誤在pyCharm和創建文件時指定UTF-8固定它。您將需要導入編解碼器來執行此操作。

import codecs 

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