stripping the first byte from a binary file
rvr
rvanroode at gmail.com
Tue Jul 10 21:06:04 EDT 2007
On Jul 10, 6:37 pm, Jeremy Sanders <jeremy
+complangpyt... at jeremysanders.net> wrote:
> rvr wrote:
> > Would someone mind showing me how to strip the first byte from a
> > binary file? For some reason I can't figure this out from the binary
> > file editing examples I've read. Thanks.
>
> Do you mean something like this?
>
> f = open('test.dat', 'rb')
> f.read(1) # read 1st byte and ignore it
> rest = f.read() # read rest
>
> or
>
> data = f.read()
> data = data[1:] # skip 1st byte
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.
~rvr
More information about the Python-list
mailing list