D
D
Dmitry Piliguzov2021-06-07 16:06:03
Python
Dmitry Piliguzov, 2021-06-07 16:06:03

How to fix error with getting sql data in python?

my code:

a = "Ваш баланс: " + str(sql.execute(f"SELECT money from users WHERE id = '{user_id}'")) + "$"
print(a)


he returns
Ваш баланс <sqlite3.Cursor object at 0x000001FBCA70AD50>$


How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yupiter7575, 2021-06-07
@yupiter7575

First of all, this is not a mistake. Secondly, execute in python, like in any other language, returns a fetch object. To pull information from there, you need to use the .fetchall () function.
For example:

cur.execute("SELECT * FROM table")

    rows = cur.fetchall()

    for row in rows:
        print(row)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question