I can't figure out what I am doing wrong. Can someone please help? When I run the following statement:
cur.execute("SELECT created FROM datafiles where path = '%s'" % self.srchfilepath.displayText()
list = cur.fetchall()
(self.srchfilepath.displayText() is just a field on a GUI)
The results I get is:
[('testing',), ('testing',)]
The actual data is correct, it is just in a format I don't understand.
I can't figure out where the extra commas within the parens are coming from. I am trying to put this data in back into a listbox field for display and selection, but I need a list that the field will accept. Clearly this is not what it wants. Can anyone tell me what I am doing wrong and how I can make the result into something the Listbox
will accept?
You retrieved a list of rows, and each row is a tuple of columns. As each row contains only one column the rows are tuples with one value each.
In python, it is the comma that makes an expression a tuple, even if there is only one element:
>>> 1,
(1,)
Simply select the first element of each row:
result_list = [row[0] for row in cur.fetchall()]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With