[FRPythoneers] Reading Binary files

Sean Reifschneider jafo at tummy.com
Mon Jan 14 16:50:24 MST 2002

On Mon, Jan 14, 2002 at 04:51:58PM -0700, J. Wayde Allen wrote:
>   calfile = open (calfilename, 'rb')  #Open the file for binary read
>   for i in range(512):
>      a = calfile.read(4)
>So how do I do the conversion to single precision?

intValue = struct.unpack('i', a)

Read the struct docs for more information.  Note that you may want to use
'<i' or '>i' to specify little or big endian.  '!i' specifies "network byte
order", which is a synonym for big-endian.  Network-order is often the
preferred byte-order.

 I used to think that the brain was the most wonderful organ in
 my body.  Then I realized who was telling me this.  -- Emo Phillips
Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
tummy.com - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python

More information about the FRPythoneers mailing list