1 回答

TA貢獻1789條經(jīng)驗 獲得超8個贊
將Tabela文件作為參數(shù)而不是硬編碼pom1.txt,并Tabela(UseFile)從OpenFile().
此外,由于您cursor.execute()使用參數(shù)調(diào)用,因此不應連接datainto的元素query,只需在查詢中放置占位符。
def OpenFile():
name = askopenfilename(initialdir="",
filetypes =(("Text File", "*.txt"),("All Files","*.*")),
title = "Choose a file."
)
print(name)
#Using try in case user types in unknown file or closes without choosing a file.
try:
with open(name,'r') as UseFile:
Tabela(UseFile)
except:
print("No file exists")
def Tabela(infile):
for line in infile:
data = line.strip().split("\t")
print(data)
query = ("INSERT INTO Pomiary_Obwod_90(Pomiar_x, Pomiar_y, Pomiar_z) VALUES (%s, %s, %s)")
cursor.execute(query, data)
con.commit()
return
添加回答
舉報