[英]Python - the SQLite database file was loaded in a wrong encoding 'UTF-8'
[英]python - file was loaded in the wrong encoding utf-8
我是編程的新手,我不明白我收到的錯誤消息, file was loaded in the wrong encoding utf-8
或者它不是代碼中的錯誤消息,但是我在新的.txt文件中得到了錯誤消息我寫所有找到的關鍵字。 .txt文件最多可以顯示4000多個行,其中包含我在另一個程序中按Excel排序的信息,然后將其發送到Access。 該消息的含義是什么,這是一種解決方法? 謝謝
我在anaconda36上使用pycharm
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修復了該錯誤。 您將需要導入編解碼器來執行此操作。
import codecs
with codecs.open(‘name.txt', 'a', 'utf-8-sig') as f:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.