以 csv 格式存储光标对象的输出
我已经访问了数据库并将结果存储在游标对象中。但我无法保存它:(
cur_deviceauth.execute('select * from device_auth')
for row in cur_deviceauth:
print row
writer = csv.writer(open("out.csv", "w"))
writer.writerows(cur_deviceauth)
我没有收到错误消息,也无法编写它。我该怎么做?任何建议都会有很大帮助,学习这些东西的最佳地点是什么?
i've accessed a database and have the result in a cursor object. but i couldn't save it :(
cur_deviceauth.execute('select * from device_auth')
for row in cur_deviceauth:
print row
writer = csv.writer(open("out.csv", "w"))
writer.writerows(cur_deviceauth)
i don't get an error msg and i couldn't write it. how do i make it? any advice would be of much help and what is the best place to learn this stuff?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您在写入文件之前打印行时,您会耗尽充当生成器的游标对象。只需写入文件,无需任何中间步骤。
When you're printing rows before writing to a file, you're exhausting cursor object that works as a generator. Just write to file without any intermediate steps.