stripping the first byte from a binary file
steven at REMOVE.THIS.cybersource.com.au
Wed Jul 11 07:28:18 CEST 2007
On Wed, 11 Jul 2007 01:06:04 +0000, rvr wrote:
> Is there a way to edit the file in place? The best I seem to be able to
> do is to use your second solution to read the file into the string, then
> re-open the file for writing and put the whole thing back (minus the
> first byte). Thanks.
I don't believe that any of the popular operating systems in common use
(Windows, Linux, Mac, *BSD) have any such functionality.
For safety, you are best off copying the file (minus the first byte) to a
temporary file, then renaming the copy over the original. That way if
your process dies midway through copying the file, you don't lose data.
Renaming the file is atomic under Linux and (probably) Mac, so it is as
safe as possible. Even under Windows, which isn't atomic, it has a
smaller margin for disaster than over-writing the file in place.
More information about the Python-list