V
V
Vlad2422022-03-15 13:41:08
Python
Vlad242, 2022-03-15 13:41:08

Why can't python see the table?

62307a6f079fd641437560.png

db = Database('db.db')
bot = telebot.TeleBot(TOKEN)


class Database:
    def __init__(self, database_file):
        self.connection = sqlite3.connect(database_file, check_same_thread = False)
        self.cursor = self.connection.cursor()

   

    def set_gender(self, chat_id, gender):
        with self.connection:
            user = self.cursor.execute("SELECT * FROM `users` WHERE `chat_id` = ?", (chat_id,)).fetchmany(1)
            if bool(len(user)) == False:
                self.cursor.execute("INSERT INTO `users` (`chat_id`, `gender`) VALUES (?,?)", (chat_id, gender))
                return True
            else:
                return False



The db.db file has been created and it has users

6230752198047131320510.png
623075cfe41f6508630542.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2022-03-15
@galaxy

The db.db file has been created and it has users

Sherche la file. It is unlikely that the file you are looking at and the one that python opens are the same file.
When the script is run, the file is searched for (or created) in the current directory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question