Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
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

Top comments (0)