Reference: https://stackoverflow.com/questions/354883/how-do-you-return-multiple-values-in-python
I just realize the python function can pass multiple values through dictionary!
Here’s the code which I tried:
import sqlite3 def connect_db(): conn = sqlite3.connect("lite.db") cur = conn.cursor() return {'conn': conn, 'cursor': cur} def create_table(conn): conn['cursor'].execute("CREATE TABLE IF NOT EXISTS store (item TEXT, quantity INTEGER, price REAL)") conn['conn'].commit() conn['conn'].close() def insert(conn, item, quantity, price): conn['cursor'].execute("INSERT INTO store VALUES(?,?,?)", (item, quantity, price)) conn['conn'].commit() conn['conn'].close() def view(conn): conn['cursor'].execute("SELECT * FROM store") rows = conn['cursor'].fetchall() conn['conn'].close() return rows if __name__ == '__main__': print(view(connect_db()))