您可以使用上下文管理器打开连接(即从池中请求一个连接):
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()