簡體   English   中英

如何從此循環中生成return語句

[英]How do I make a return statement from this loop

我有這個代碼,我需要把lastrowid作為一個返回語句。 我該如何解決呢?

def main():   
   while True:      
      #code here
      for item in name2:#break              
         conn = sqlite3.connect("foods.db")
         cursor = conn.cursor()               
         cursor.execute("INSERT INTO INPUT33 (NAME) VALUES (?);", (name2,))      
         cursor.execute("select MAX(rowid) from [input33];")
         conn.commit() 
         conn.close()      
         for rowid in cursor:break         
         for elem in rowid:
             return rowid#this is not working

            print(m)

關閉了數據庫 ,因此任何游標都無法再訪問數據。 在關閉之前檢索數據。 我在這里假設你有理由在這里循環重新打開數據庫。

def main():   
    while True:      
       for item in name2:
           conn = sqlite3.connect("foods.db")
           cursor = conn.cursor()
           with conn:             
               cursor.execute("INSERT INTO INPUT33 (NAME) VALUES (?);", (name2,))      
               cursor.execute("select MAX(rowid) from [input33];")
               rowid = cursor.fetchone()[0]
           conn.close()
           return rowid

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM