[Tutor] Saving file changes to output
Remco Gerlich
scarblac@pino.selwerd.nl
Wed, 2 Aug 2000 19:14:08 +0200
On Wed, Aug 02, 2000 at 12:54:46PM -0400, Daniel D. Laskey, CPA wrote:
<snip>
> # rebuild the file using the new position [4] with double quotes
> out_file.write(line,f3)
Instead of this, put:
out_file.write(f3)
> out_file.close()
> in_file.close()
<snip>
> #Traceback (innermost last):
> # File "today.py", line 15, in ?
> # out_file.write(line,f3)
> #TypeError: read-only buffer, tuple
>
> My objective is to write the changes I made to the data to my out_file. When I
> put a print statement after the f3 the file looks fine. I just can't get it to print
> to the junk2.txt file properly.
Just use out_file.write(f3), not (line,f3). That writes the line "f3" to
the file. You need to add a "\n" to f3 too, to go to the next line.
If you write write(line,f3), Python thinks you send the function a tuple, and
it doesn't work.
--
Remco Gerlich, scarblac@pino.selwerd.nl