Store SQLite 3 Data as a Variable in Python

后端 未结 1 1360
旧时难觅i
旧时难觅i 2021-01-28 15:33

Is it possible for me to take data stored in a sqlite3 table and use it as a Python variable? I\'m looking for something that might be similar to this pseudo-code:



        
相关标签:
1条回答
  • 2021-01-28 15:48

    To read a single value from a table, use a SELECT query that returns a result with a single row and a single column:

    for row in cursor.execute("SELECT MyColumn FROM MyTable WHERE ID = ?", [123]):
        variable = row[0]
        break
    else:
        variable = 0  # not found
    
    0 讨论(0)
提交回复
热议问题