Binary File Editor

Clarence Gardner clarence at netlojix.com
Thu Aug 17 11:19:50 EDT 2000


On Thu, 17 Aug 2000, garbett at my-deja.com wrote:
>In article <8nemvc$d1j$1 at nnrp1.deja.com>,

>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???

Use the struct module.  It will pick native integers, short integers, etc
out of a string.



More information about the Python-list mailing list