python问题求教:Cannot operate on a closed cursor。
写了一个简单的数据库查询方法,在下边想要调用时,报错:sqlite3.ProgrammingError: Cannot operate on a closed cursor.
方法
def select_data(): conn = sqlite3.connect(dbpath)
cur = conn.cursor()
sql = "select VC_FUNDCODE from data_ds limit 100;"
fund_list = cur.execute(sql)
cur.close()
conn.close()
return fund_list
调用
fund_list = select_data()datalist = []
for item in fund_list:
datalist.append(item)
print(datalist)
返回
Traceback (most recent call last):
File "/Users/chinalife/Desktop/source/flaskTiantian/database.py", line 70, in <module>
for item in fund_list:
sqlite3.ProgrammingError: Cannot operate on a closed cursor.
回答:
因为你已经调用close关闭了数据库连接
以上是 python问题求教:Cannot operate on a closed cursor。 的全部内容, 来源链接: utcz.com/a/163850.html