【发布时间】:2017-12-23 21:21:34
【问题描述】:
我使用 pypyodbc 从 ms sql 服务器读取数据。
我不确定是否应该在任何查询后关闭游标,或者只在最后关闭一次,我在文档中找不到任何内容。
例子:
curs = con.cursor()
for id in id_list:
curs.execute ('Select * from XXX where id = {}'.format (id))
curs.fetchall ()
# Write the data into the target...
# curs.close() ???
curs.close()
这对吗?
谢谢
【问题讨论】:
-
完成后关闭光标。
-
如果它实现了游标的标准 PEP (python.org/dev/peps/pep-0249) ,那么相关:stackoverflow.com/questions/5669878/…