M
M
MIL_12342021-10-14 23:30:52
Python
MIL_1234, 2021-10-14 23:30:52

How to read data from database into sqlite using python?

The user has a city in the database, for example "Moscow". Outputting it with code:

cursor.execute("SELECT bdname FROM user_city")
place = str(cursor.execute)

The city is displayed like this:
<built-in method execute of sqlite3.Cursor object at 0x00000201140B82D0>

Tell me what could be the problem, and how else can I display one data from the database.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-10-15
@Vindicar

Because you need to read the documentation , there are code examples on the very first couple of pages, including a SELECT query.
What do you expect to get by calling str(cursor.execute) if you know that cursor.execute() is a method?
And why are you ignoring its return value when you make a request?
More shortly, once again - read docks. They are helpful.

for row in cursor.execute('SELECT bdname FROM user_city'):
        print(row)

A
alexbprofit, 2021-10-15
@alexbprofit

https://cppsecrets.com/users/110711510497115104971...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question