K
K
Kemper54542022-02-19 16:55:57
Python
Kemper5454, 2022-02-19 16:55:57

UnboundLocalError: local variable 'metawallet' referenced before assignment. What to do?

Here is a code snippet:

def get_metawallet(self,  user_id):
    with self.connection:
        result = self.cursor.execute("SELECT `wallet` FROM `users` WHERE `user_id` = ?", (user_id,)).fetchall()
        for row in result:
            metawallet = str(row[0])
        return metawallet

I googled everything I could and couldn't find it. Hope someone can help me. I am newbie

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2022-02-19
@Kemper5454

If there is no line in result, what value will metawallet have?

A
Alexander Nesterov, 2022-02-19
@AlexNest

I googled everything I could and couldn't find it.

I highly doubt it.
The point is that you are declaring metawallet in a loop that loops through a tuple of values ​​retrieved from the database.
It is far from a fact that the database contains suitable data. In addition, with each iteration, the data will be overwritten.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question