Binary File Editor

Alex Martelli alex at magenta.com
Thu Aug 17 11:32:37 EDT 2000


<garbett at my-deja.com> wrote in message news:8ngnev$ln2$1 at nnrp1.deja.com...
    [snip]
> The first four bytes of the file are a string denoting type, the next
> four is an integer.
>
> Quite simply, how do I read the first four bytes into a string and the
> next four into an integer in python? If I can do this I think the rest
> is downhill.
>
> The FileType supports a read, i.e. 'f.read([n])  Reads at most n bytes'
> but how could this be used to read into python native types???

import struct

thestring,theint=struct.unpack('4si',f.read(8))


Alex






More information about the Python-list mailing list