I got this code:
cursor.execute('SELECT nom FROM productes WHERE listacompra = 1')
producteslc = cursor.fetchone()
The problem is that when I do print producteslc, it returns (u'Natillas',), when the value on the SQL Database is just Natillas.
What could I do to have a variable with value = Natillas? I'm trying to do some stuff with split but I'm not able to do it at my own.
Thank you
The result of
fetchoneis a tuple of the values of one row.Since you only fetch a single column, the result is a tuple singleton:
(u'Natillas',)To get the string:
See: Tuples and Sequences in the doc
EDIT
To fetch several rows, you can use
fetchall()function:To print each name.