On Wed, Feb 25, 2009 at 1:53 PM, Alan Gauld <[email protected]> wrote: > > "Bala subramanian" <[email protected]> wrote > >> query 1) How should i overwrite the input file >> I want to open 5 files one by one, do some operation on the lines and >> write >> the modified lines on the same file (overwritting). Can some please tell >> me >> how to do it. > > You don't really want to do that! Too risky. > Better to do what you are doing and then when it has all worked > and you close both input and output files you can delete the > original and rename the outfile to the original input file name. > In fact to be really safe don't delete the old file but rename > it to .bak...
The fileinput module with inplace=1, backup='.bak' does close to what you are describing. It renames the input file before opening it, so if there is a failure it will be renamed. Kent _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
