問題:
python 程序需要不停訪問數據庫,獲取數據進行處理, 但查詢結果為空時,如何處理?
關鍵點:
while 循環 、 continue 退出 循環 、 if not
解決偽代碼:
def main():
while True:
print(datetime.now(),'INFO : begin ******************************' )
query_sql = 'select xxx'
result = exec_query_sql(query_sql)
if not result : # 即result是空的時候
print(datetime.now(),'Waring : no query result, sleep 60s' )
time.sleep(60)
continue # 退出本次while循環,執行下一次
for res_tuple in result:
# do something
main()
