使用pandas“read_sql_query”时,是否需要关闭连接?或者我应该使用“with”语句?或者我可以使用以下并且好吗?
from sqlalchemy import create_engine
import pandas as pd
sql = """
SELECT * FROM Table_Name;
"""
engine = create_engine('blah')
df = pd.read_sql_query(sql, engine)
print df.head()
Looking at the source code,我找不到任何SQL连接对象的con.close()
方法,只查询cursor
对象。
我会关闭安全措施。无论你是否使用with
这样做取决于你。
对于那些发现这个问题并想知道如何在这个例子中关闭连接的人来说,following method为我工作:engine.dispose()