S
S
sousagemonster2021-04-06 20:03:40
Python
sousagemonster, 2021-04-06 20:03:40

How to print column value from sqlite in python?

Used this code

cur.execute("SELECT balance from users where userid = ?", (message.from_user.id,))

But as I was told, it outputs an array, not a value, as I would like

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
uprj, 2021-04-07
@sousagemonster

You just need to write the zero index of the array, this will be the value. for example

cur.execute("SELECT balance from users where userid = ?", (message.from_user.id,))
balance = cur.fetchone()
balance = balance[0]

First, we extract the first (it is the only) value, and then we take the zero index from it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question