Writing to files

Deirdre Saoirse deirdre at deirdre.net
Mon Mar 20 18:30:42 EST 2000


On Mon, 20 Mar 2000, Daley, MarkX wrote:

> a=some list ([1,2,3,whatever])
> f=open('filename','a')
> 
> 	for x in a:
> 		f.write(a[x])

x isn't an integer, it's the hunk of a at that subscript (what you're
thinking of as a[x], it already is). What you need:

       for x in a:
               f.write(x)

-- 
_Deirdre   *   http://www.linuxcabal.org   *   http://www.deirdre.net
       "In /dev/null, no one can hear you scream"





More information about the Python-list mailing list