i have this code:
cur.execute("SELECT numbers FROM table")
supp = cur.fetchall()
for item in supp:
print item
and it prints:
('one',)
('two',)
('three',)
how can i have?
one
two
three
i have this code:
cur.execute("SELECT numbers FROM table")
supp = cur.fetchall()
for item in supp:
print item
and it prints:
('one',)
('two',)
('three',)
how can i have?
one
two
three
Each item
correspond to a row of a result of your query, each row is represented by a tuple. If you want to get the first items of every tuple, you can unpack them in the for
loop:
for value, in supp:
print(value)
Or, you can just get the first items by index as well:
for row in supp:
print(row[0])
You can also put them into a list with a list comprehension:
values = [value for value, in supp]
Demo:
>>> supp = [('one',), ('two', ), ('three', )]
>>> for value, in supp:
... print(value)
...
one
two
three
>>> [value for value, in supp]
['one', 'two', 'three']
try:
supp = cur.fetchall()
for item in supp:
print ' | '.join(item)
return "values printed"
except:
return "Something went wrong!"