Is Python suitable for some binary file editing?

David Bolen db3l at fitlinxx.com
Wed Dec 5 19:54:34 EST 2001


Tim Hammerquist <tim at vegeta.ath.cx> writes:

> I'd have preferred:
> 
> Replace 2 bytes in place beginning at offset 100 (101st byte):
> 
>     f = open('text_input', 'r+b')
>     f.seek(100)
>     f.write(chr(123) + chr(0x80))
>     f.seek(0,2)
>     f.close()

That would work too, but not for the original request, which was to
have a separate copy:

David Rollo <drollo at cns.net.au> wrote:
> The file conversion is simply making the same change to a handful of
> characters at a particular offset, and saving under a new filename.

so I don't think he wanted to modify the original files.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list