find and replace string in binary file
Chris Angelico
rosuav at gmail.com
Tue Mar 4 17:44:03 EST 2014
On Wed, Mar 5, 2014 at 12:18 AM, Peter Otten <__peter__ at web.de> wrote:
> loial wrote:
>
>> How do I read a binary file, find/identify a character string and replace
>> it with another character string and write out to another file?
>>
>> Its the finding of the string in a binary file that I am not clear on.
>
> That's not possible. You have to convert either binary to string or string
> to binary before you can replace. Whatever you choose, you have to know the
> encoding of the file.
If it's actually a binary file (as in, an executable, or an image, or
something), then the *file* won't have an encoding, so you'll need to
know the encoding of the particular string you want and encode your
string to bytes.
ChrisA
More information about the Python-list
mailing list