Is Python suitable for some binary file editing?

Bengt Richter bokr at accessone.com
Thu Dec 6 02:34:26 EST 2001


On 05 Dec 2001 19:54:34 -0500, David Bolen <db3l at fitlinxx.com> wrote:

>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.
>
Even if he did, he might want to be sure he had a valid new file before
eliminating the original.



More information about the Python-list mailing list