Answer the question
In order to leave comments, you need to log in
Why is it not connecting to the SQLightStudio database?
I am writing a bot. The task is to connect to the database and assign the data to a variable, which the bot will then display. Why is there an error in the console:
File "bot.py", line 13, in product
with connect('database.db') as connection:
NameError: name 'connect' is not defined
def product(name ):
with connect('database.db') as connection:
cursor = connection.cursor()
cursor.execute("SELECT * FROM catalog WHERE name = ? ", (name,))
result = cursor.fetchone()
return result
Answer the question
In order to leave comments, you need to log in
Something like this should be:
import sqlite3
def product(name):
with sqlite3.connect('database.db') as connection:
cursor = connection.cursor()
cursor.execute("SELECT * FROM catalog WHERE name = ? ", (name,))
return cursor.fetchone()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question