Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67743
| References | <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> <lf4jrk$95v$1@ger.gmane.org> |
|---|---|
| Date | 2014-03-05 09:44 +1100 |
| Subject | Re: find and replace string in binary file |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7760.1393973045.18130.python-list@python.org> (permalink) |
On Wed, Mar 5, 2014 at 12:18 AM, Peter Otten <__peter__@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
find and replace string in binary file loial <jldunn2000@gmail.com> - 2014-03-04 04:27 -0800
Re: find and replace string in binary file MRAB <python@mrabarnett.plus.com> - 2014-03-04 13:08 +0000
Re: find and replace string in binary file Peter Otten <__peter__@web.de> - 2014-03-04 14:18 +0100
Re: find and replace string in binary file Chris Angelico <rosuav@gmail.com> - 2014-03-05 09:44 +1100
Re: find and replace string in binary file emile <emile@fenx.com> - 2014-03-04 16:13 -0800
Re: find and replace string in binary file loial <jldunn2000@gmail.com> - 2014-03-05 01:59 -0800
Re: find and replace string in binary file Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-05 12:42 +0000
Re: find and replace string in binary file Emile van Sebille <emile@fenx.com> - 2014-03-05 09:46 -0800
Re:find and replace string in binary file Dave Angel <davea@davea.name> - 2014-03-05 07:06 -0500
csiph-web