Reputation:
I have three values stored inside my SQLite
Table, i.e. question-hyperlink
, excerpt
, pl8 js-gps-track nav-links--link
.
I want them to get each value inside a separate variable.
For example :
x = question-hyperlink
,
y = excerpt
and
z = pl8 js-gps-track nav-links--link
.
Here is my code :
import sqlite3
cur.execute("""CREATE TABLE Classes (id VARCHAR(30));""")
cur.execute("""INSERT INTO Classes VALUES ("question-hyperlink");""")
cur.execute("""INSERT INTO Classes VALUES ("excerpt");""")
cur.execute("""INSERT INTO Classes VALUES ("pl8 js-gps-track nav-links--link");""")
conn.commit()
cur.execute("""select * from Classes;""")
for class_Names in cur.fetchall():
print(class_Names)
This gives me :
('question-hyperlink',)
('excerpt',)
('pl8 js-gps-track nav-links--link',)
I have tried nested loops for this but failed. How to get them a seperate variable as listed in the example above?
Any help would be appreciated...
Upvotes: 1
Views: 59
Reputation: 9494
Maybe try the following:
all_values = tuple()
for class_Names in cur.fetchall():
# let's merge all tuples into one
all_values += class_Names
# then we can upack the tuples into different variables
x,y,z = all_values
Upvotes: 2