使用連線

你可以使用上下文管理器開啟連線(即從池中請求一個連線):

with engine.connect() as conn:
    result = conn.execute('SELECT price FROM products')
    for row in result:
        print('Price:', row['price'])

或者沒有,但必須手動關閉:

conn = engine.connect()
result = conn.execute('SELECT price FROM products')
for row in result:
    print('Price:', row['price'])
conn.close()