我仍在尝试用我创建的日历小部件的结果填充查询。日历小部件工作正常,如果消息框的回答是肯定的,则weeklyrpt.py可以正常工作。没有响应会打开日历窗口小部件,其中选择日期并单独解析,但我无法弄清楚如何将结果集成到我的查询中。
rundate函数是
def rundate():
global run
result = tkinter.messagebox.askyesno(title="Rundate", message="back 7 days?")
#result = tkinter.messagebox.askyesno()
if result == True:
run = date.today() - timedelta(7)
return run
if result == False:
os.system("python pick.py")
#opens the pick.py program which is a calendar the after choosing the dates returns this function
def get_rundate():
start = self.result1.strftime("%m/%d/%Y")
end = self.result2.strftime("%m/%d/%Y")
daterange = pd.date_range(start, end)
for single_date in daterange:
print(single_date.strftime("%m/%d/%Y"))
return single_date.strftime("%m/%d/%Y")
#then returns to weeklyreport
rundate = rundate()
print(rundate)
我试图为查询获取的数据是“rundate”
#Query permits made effective since rundate
query = '''select `NPDES_ID`, `EffectiveDate`, `FacilityName`, `StateFacilityID`, `City`, `CountyName`
from Permits
where `EffectiveDate` >= ?
order by `NPDES_ID`'''
#for each row in result of query
for row in cur.execute(query, (rundate)):
try:
d= row[1].strftime('%m/%d/%Y')
except:
d=""
for i in range(len(row)):
if not row[i]:
row[i] = ""
我需要帮助从pick.py小部件获取结果,以在weeklyrpt.py中作为rundate返回。正如我所说,rundate函数的第一部分工作正常(返回数据请求返回7天)
答案 0 :(得分:0)
我不知道这是否是唯一的问题,但肯定 问题是:
for row in cur.execute(query, (rundate)):
(rundate)
是单个值,(rundate,)
是一个元组。 cur.execute
需要一个元组。