Convert sql result to list python

后端 未结 5 680
醉话见心
醉话见心 2021-02-05 19:17

im beginner with python.I want to convert sql results to a list.Here\'s my code:

cursor = connnect_db()

query = \"SELECT * FROM `tbl`\"

cursor.execute(query)

         


        
5条回答
  •  臣服心动
    2021-02-05 19:36

    if you are using stored procedure you can convert results to list like this.

    
    cursor = connection.cursor()
    parameters = []
    cursor.callproc('spProcedureName', parameters)
    resultList =[r.fetchall() for r in cursor.stored_results()][0]
    cursor.close()
    
    

提交回复
热议问题