Python: tuple indices must be integers, not str when selecting from mysql table

前端 未结 7 1631
梦谈多话
梦谈多话 2021-01-01 14:08

I have following method that I select all the ids from table and append them to a list and return that list. But when execute this code I end up getting tuple indicies must

7条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-01 14:58

    you can see here: enter link description here ,I think its your want

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    
    import sqlite3 as lite
    
    
    con = lite.connect('test.db')    
    
    with con:
    
        con.row_factory = lite.Row # its key
    
        cur = con.cursor() 
        cur.execute("SELECT * FROM Cars")
    
        rows = cur.fetchall()
    
        for row in rows:
            print "%s %s %s" % (row["Id"], row["Name"], row["Price"])
    

提交回复
热议问题