[Tutor] Iterating writing in a file
Christian Wyglendowski
Christian.Wyglendowski at greenville.edu
Tue Jul 13 23:20:45 CEST 2004
To open a file for writing, the syntax is as follows:
sFile = 'C:\\myFile.txt'
oFile = file(sFile, 'w')
See the documentation on the built-in funtion "file" for more
information:
http://docs.python.org/lib/built-in-funcs.html#built-in-funcs
Christian
http://www.dowski.com
________________________________
From:
tutor-bounces+christian.wyglendowski=greenville.edu at python.org
[mailto:tutor-bounces+christian.wyglendowski=greenville.edu at python.org]
On Behalf Of Bernard Lebel
Sent: Tuesday, July 13, 2004 4:25 PM
To: tutor at python.org
Subject: [Tutor] Iterating writing in a file
Hello,
I wish to do an iteration that will write something on each new
line in a
text file. Something like this:
sFile = 'C:\\myFile.txt'
oFile = file( sFile, 'rw' )
for oLine in range(1,10):
oFile.write( 'text' )
However when I run this I get an IO error for the oFile.write()
line.
Any suggestion?
Thanks
Bernard
More information about the Tutor
mailing list