2017-06-21 41 views
0

私はプログラミングにかなり新しいです。私はこのエラーメッセージを理解していません。file was loaded in the wrong encoding utf-8またはそれは実際にはコード内のエラーメッセージではありませんが、私の新しい.txtファイルどこに私はすべての見つけたキーワードを書く。 .txtファイルは、別のプログラムでExcelにソートして後でAccessに送信する情報を使用してuppを4000+行に取得します。メッセージは何を意味し、それを修正する方法はありますか? anaconda36python - ファイルが間違ったエンコーディングで読み込まれました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 im anacondaとpycharmを使用しています – fili

答えて

0

でpycharmを使用してのおかげ

イムは、私はちょうどpyCharmで同じエラーを持っていたし、ファイルを作成するときにUTF-8を指定して、それを修正しました。これを行うには、コーデックをインポートする必要があります。

import codecs 

with codecs.open(‘name.txt', 'a', 'utf-8-sig') as f: 
関連する問題