def function1():
conn = sqlite3.connect('mydb.db')
connection = conn.cursor()
return conn, connection
def function2(conn, connection):
conn.execute("""
INSERT INTO category
(cat_name)
VALUES (?) """, (cat,)
)
conn.commit()
def main():
connection = function1()
categories = function2(conn, connection)
它没说:
categories = function2(conn, connection)
NameError: name 'conn' is not defined
知道为什么吗?谢谢
答案 0 :(得分:0)
您从未在main()中定义conn
。可能你想在connection
中使用元组的值。
E.g。
conn, connection = function1()
categories = function2(conn, connection)