'How do I load a .sql file in a python environment?

I have a .sql file which I'm trying to load in an online Python environment (JupyterHub) but other code I've found online has just left me confused. I've gotten as far as:

import sqlite3
from sqlite3 import connect
sqlite_uri = "sqlite:///basketball.db"
sqlite_engine = sqlalchemy.create_engine(sqlite_uri)

connection = sqlite3.connect(":memory:")

cursor = connection.cursor()

sql_file = open("travel-times.sql")

travel = sql_file.read()
travel

sql_expr = """
SELECT *
FROM travel;
"""

pd.read_sql(sql_expr, sqlite_engine)

and calling the 'travel' object does at least print the data in raw form, but from there I'm at a loss to actually load the table from here. What commands would accomplish this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source