[Tutor] Iterating writing in a file (original) (raw)
Christian Wyglendowski Christian.Wyglendowski at greenville.edu
Tue Jul 13 23:20:45 CEST 2004
- Previous message: [Tutor] Re: Please critique my guessing game program.
- Next message: [Tutor] Iterating writing in a file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 newline 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- Previous message: [Tutor] Re: Please critique my guessing game program.
- Next message: [Tutor] Iterating writing in a file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]