views:

22

answers:

1

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?

+2  A: 

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.

SilentGhost
+1: Cursors (like other generator functions) can only be used once.
S.Lott