我对编程相当陌生,我不理解我得到的这个错误消息,file was loaded in the wrong encoding utf-8
或者它不是代码中的错误消息,但是我在我的新的.txt文件中得到了它,我在其中写入了所有找到的关键字。txt文件将upp到4000多行,其中包含我在另一个程序中对Excel进行排序,然后将其发送到Access。这个信息是什么意思?有没有办法解决它?谢谢
我用pycharm和Python36
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')
我只是在pyCharm中遇到了相同的错误,并在创建文件时指定了UTF-8来修复它。您需要导入编解码器才能完成此操作。在
相关问题 更多 >
编程相关推荐