Writing to files
Joshua Macy
amused at webamused.com
Mon Mar 20 18:40:57 EST 2000
"Daley, MarkX" wrote:
>
> >
> I didn't realize print converts to a string. I guess the question I should
> ask then, is how do I write a list to a file item by item?
>
> - Mark
for x in a:
f.write(x)
is the right idea, but you might have to coerce x into a string, since
that's what write expects. E.g.
for x in a:
f.write(str(x))
ought to work, unless one of the objects in a fails to support a string
representation.
Joshua
More information about the Python-list
mailing list