How to Iterate through cur.fetchall() in Python

前端 未结 5 921
刺人心
刺人心 2021-01-02 18:18

I am working on database connectivity in Python 3.4. There are two columns in my database.

Below is the query which gives me all the data from two columns in shown f

5条回答
  •  独厮守ぢ
    2021-01-02 18:44

    To iterate over and print rows from cursor.fetchall() you'll just want to do:

    for row in data:
        print row
    

    You should also be able to access indices of the row, such as row[0], row[1], iirc.

    Of course, instead of printing the row, you can manipulate that row's data however you need. Imagine the cursor as a set of rows/records (that's pretty much all it is).

提交回复
热议问题