python records 报错 Cannot operate on a closed database
原创
©著作权归作者所有:来自51CTO博客作者TechOnly的原创作品,请联系作者获取转载授权,否则将追究法律责任
import records
db = records.Database('sqlite:///{}'.format("predict.db"))
print()
out= db.query('SELECT COUNT(stock_name) from STOCK WHERE sp500_2018 = "true" and nasdaq_2018 = "true"')
for item in out:
print(item["COUNT(stock_name)"])
改成
import records
db = records.Database('sqlite:///{}'.format("predict.db"))
db = db.get_connection() # 新加
print()
out= db.query('SELECT COUNT(stock_name) from STOCK WHERE sp500_2018 = "true" and nasdaq_2018 = "true"')
for item in out:
print(item["COUNT(stock_name)"])