[Tutor] in as a stream, change stuff, out as a stream?
ak@silmarill.org
ak@silmarill.org
Wed, 11 Jul 2001 21:13:36 -0400
On Wed, Jul 11, 2001 at 05:42:16PM -0700, Israel Evans wrote:
> 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.
there's also xreadlines()
>
> 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.
I'd read a line, change it, write it to a temp file, when done overwrite old
file with new.
>
> 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~
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: http://silmarill.org/cymbaline