views:

17

answers:

2

I have accessed a database and have the result in a cursor object. when I try to save it to a text file, python says

TypeError: argument 1 must be string or read-only character buffer, not sqlite3.Cursor

can someone tell me what I should do here?

curobject.execute('select * from device_auth')  
for row in curobject:  
        print row  
myfile =open('out.txt', 'w')  
myfile.write(curobject)
A: 

For example something like this:

with open('out.txt', 'w') as file:
    file.writelines(', '.join(row) + '\n' for row in curobject)    # assuming row of strings
SilentGhost
hi.. what would be the best way to store the output in my case? as i want to compare it with another output? and btw, thanks for the edit ;)
The Learner
+1  A: 

You can't just write objects to a file, you have to either serialize them or write your own string representation of the object. For records of a database the csv module could make sense.

Which approach is better depends on what you want to do with the file later.

Fabian
i am not sure bout choosing the right approach since i'm fairly new to python.. here's what i want to do. After storing the output, i'll have to compare it with another output that i stored elsewhere.. pls guide me the suitable one..
The Learner