C
C
ch1ps012022-03-25 20:40:12
SQLite
ch1ps01, 2022-03-25 20:40:12

Problem with fetchall(). Can you help?

con=sqlite3.connect('users.db')
cur=con.cursor()

cur.execute("SELECT name FROM reviews")
name=cur.fetchall()[1]
cur.execute("SELECT text FROM reviews")
text = cur.fetchall()[1]
print(f'{name}:\n{text}')

This code sends the user a name and a review from the database, but instead of sending just a name and text, there are also brackets and commas from the array, how can I remove them and leave only the name and text?
('Valentine',):
('aa',)

Process finished with exit code 0

Thanks in advance for your reply

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gd1xza, 2022-03-25
@ch1ps01

So?

con=sqlite3.connect('users.db')
cur=con.cursor()

cur.execute("SELECT name FROM reviews")
name=cur.fetchall()[1][0]
cur.execute("SELECT text FROM reviews")
text = cur.fetchall()[1][0]
print(f'{name}:\n{text}')

A
Alexander, 2022-03-25
@shabelski89

Reading a textbook, not writing bots. What are tuples, lists, slices.

example = ('Valentine',)
example[0]
'Valentine'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question