Hey all!

i need to write a tuple into a file..

it was to work something like this:

----

c.execute('select * from valores')

for row in c:
	file1.write(row)

-----
i already tried to do str(row) and everything, but nothing seems to work...

Recommended Answers

All 4 Replies

ok

i think i made it...

here is what ive done..

c.execute('select * from valores')

for row in c:
	arquivo1.write(" ".join(row))
	arquivo1.write("\n")

What didn't work about str(row)? What kind of error did you get? The only thing I can think of is that you didn't add any line endings?

>>> import os
>>> os.linesep
'\r\n'

This depends on the type of system you're on. \r\n is Windows, \n is Linux, and I believe that \r is Mac (although I've never used one so I don't really know).

This depends on the type of system you're on. \r\n is Windows, \n is Linux, and I believe that \r is Mac (although I've never used one so I don't really know).

Yer thats the correct line endings for each different OS, and if you intend to have it portable make sure you do some kind of check as to what os is running and append the correct line endings otherwise you will have some problems

you can use the pprint module to format lists, tuples or dictionaries into readable strings...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.