S
S
Setkh2021-04-07 04:15:32
Python
Setkh, 2021-04-07 04:15:32

How to get a variable in its normal form?

Hello, I'm facing the following problem:

def check_balance(self, user_id):
        with self.connection:
            coin = self.cursor.execute("SELECT `coin` FROM `subscriptions` WHERE `user_id` = ?", (user_id,)).fetchone()
            return coin

The variable is obtained in the following format: (5,) It is
necessary to get only a digit, how to do it?
With the help of regular expressions or is there some more rational solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zexer, 2021-04-07
@Setkh

What's stopping you from taking the [0] element from that result?

H
HemulGM, 2021-04-07
@HemulGM

Is it really difficult to make a small effort, which can not even be called an effort, and find out what execute returns ? It does not return a string. It's your print that converts to a string and shows you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question