Answer the question
In order to leave comments, you need to log in
How to fix error with database SQLite in Python?
import sqlite3
class Database:
def __init__(self, db_file):
self.connection = sqlite3.connect(db_file)
self.cursor = self.connection.cursor
def add_check(self, user_id, bill_id):
with self.connection:
self.cursor .execute("INSERT INTO 'check' ('user_id', 'bill_id') VALUES (?,?)", (user_id, bill_id,))
Tell me where, what I wrote wrong, gives an error:
'builtin_function_or_method' object has no attribute 'execute'
Answer the question
In order to leave comments, you need to log in
Try this solution.
class DataBase:
def __init__(self, db_file):
self.conn = sqlite3.connect(db_file)
self.cur = self.conn.cursor()
# Аргумент arg принимает только кортежи(tuple), иначе ошибка.
def add_check(self, arg: tuple):
self.cur.execute("INSERT INTO check VALUES(?, ?);", arg)
self.conn.commit()
# Создаем экземпляр класса, с указанием на БД.
db = DataBase('bot_base.db')
# Передаем методу класса add_check кортеж состоящий из user_id и bill_id
db.add_check((user_id, bill_id))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question