[Tutor] in as a stream, change stuff, out as a stream?

Israel Evans israel@lith.com
Wed, 11 Jul 2001 17:42:16 -0700


Hello, 

I'm in the middle of reading a bunch of rather large files in order to
change one string to another.  I'm probably missing something extremely
obvious, but that's what this glorious Tutor Mailing list is all about isn't
it?  I've been reading the documentation, and due to my newbie status, I
can't find the right "aha!" yet, so any help would be most appreciated

I know I should be able to open up a file, read all of it's contents into a
list with readlines() or read one line at a time with readline(), and then
write all of that out to another file.  I think that since the files are
rather large, it might be best to avoid the speed of readlines() and go with
readline() repeatedly.

At any rate, I was wondering if it would be possible to read a line, change
it in the same file I'm reading and move on to the next line, when I'm done.
Is this possible?  Or should I read everything at once, change the name of
the old file and write everything out to a file with the same name as the
old one.  

Is it possible to open a file as a stream  and output it back into itself?
or is that just plain goofy.

I'm trying to do this bit with a number of fairly large files in multiple
directories, and so it would be ideal If I didn't have to fill up my hard
drive with old copies.

~Israel~