read and write binary data (newbie)
rich at worldsinfinite.com
Tue Feb 12 15:41:33 CET 2002
On Tuesday 12 February 2002 10:45 am, Marcus Stojek wrote:
> 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:
> 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?
Try the struct module.
More information about the Python-list