开发者

storing the output of a cursor object in csv format

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')  
fo开发者_Python百科r 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜