Hackerss.com

hackerss
hackerss

Posted on

Python How to connect to sqlite


import sqlite3

def connect_to_sqlite(db_name):
    """
    Connect to a sqlite database.

    Parameters
    ----------
    db_name : str
        The name of the database to connect to.

    Returns
    -------
    sqlite3.Connection
        The connection to the database.
    """

    #connect to the database
    conn = sqlite3.connect(db_name)

    #return the connection
    return conn

#example
conn = connect_to_sqlite('test.db')
#output
print(conn)  #<sqlite3.Connection object at 0x7f8b9d8b5e90>


Enter fullscreen mode Exit fullscreen mode

Oldest comments (0)