read and write binary data (newbie)

Rich Harkins rich at worldsinfinite.com
Tue Feb 12 09:41:33 EST 2002


On Tuesday 12 February 2002 10:45 am, Marcus Stojek wrote:
> Hi,
>
> I am using Python quite a while for all kind of things. Now i have to
> read a file (Windows) in binary format that contains strings (\0
> terminated), int and floats (4 byte). and I am stunned because
> I don't know how to.
>
> to read strings I have written a function:
[snip]
>
> reading ints and floats is easy:
> x= dat.read(4)
>
> but how can i convert x into a number?
> and how can I write a float or int into
> a binary file?
>
> Could anybody please tell me where to look?
>
> thanks
> marcus

Try the struct module.  


Rich




More information about the Python-list mailing list