Peter Mexbacher wrote:
> Hello,
> 
> first post here :-)
> 
> I have the following task:
> 
> 1) read in a file line by line
> 2) parse each line with a regular expression, and substitute certain 
> patterns
> 3) end result: the old file with the substituted stuff (and of course 
> everything which did not need substitution)
> 
> My question:
> 
> Do I have to write each line out to a new file, and then rename, or can
> I substitute "in place" - that the changes are incorporated in the old
> file automatically?

The "write out to new file" approach is the generally accepted
method. FWIW, if the file were small enough, you could read
it in in its entirety and overwrite immediately without the
rename step, but you obviously have no fallback then if things
go wrong!

TJG
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to