Python psycopg2 library fetchall() list data output method?

Asked 1 years ago, Updated 1 years ago, 91 views

fetchone() is data[0] output and fetchall() is data[0] output ('data1',).

For fetchphone(), you cannot import data1, data2 because you import only one line of the table gel. So data1,data2 is imported, but it contains parentheses and commas, not pure kernel values, so can it be purely kernel values? I would appreciate it if you could share a way to refer to it.

python database psycopg2 fetchall

2022-09-21 16:30

1 Answers

If you look at the document , it's tuple rather than parentheses and commas... Would it be helpful to turn demo like this?

data2 = [('data1',), ('data2',) ('data3',)]
newlist = [data[0] for data in data2]
print(newlist)
# ["Data1", "Data2", "Data3"]


2022-09-21 16:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.