Python Forum

Full Version: Python Variables and Sqlite3 Database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there any way to pull each column entry and make each db entry it's own variable? I know how to pull a single entry at a time using something like

for rows in cursor.execute("SELECT commands FROM CR WHERE ID = [1]):
variable=rows
print(variable)
else:
variable = 0

But I need a way to make variable1 = (column entry 1), Variable2 = (column entry 2), so on and so forth. I'm assuming I would have to use arrays but can't find any guidance online. Any help would be greatly appreciated. Thanks.
I figured it out. If anyone else needs to do this... Here is the correct code...

for i in range(1,3):
print(i)
cur.execute("SELECT commands FROM CR WHERE ID=?", (i,))