[FRPythoneers] Reading Binary files

J. Wayde Allen wallen at its.bldrdoc.gov
Mon Jan 14 16:51:58 MST 2002


I have a Basic program that reads a binary file, and need to port this to
Python.  I've never really tried reading binary files with Python before
so am having a bit of difficulty.

The lines of Basic that I've got are:

    OPEN cfile$ FOR BINARY AS #1
    FOR	i = 1 TO 512
    a$ = INPUT$(4,1)  'Get 4 byte binary data
    f(i) = CVS(a$)    'Convert to single precision
    NEXT i
    CLOSE #1

What I've done for the Python version is:

   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?

- Wayde
  (wallen at its.bldrdoc.gov)

   --------------------------------------------------------
                        ISART 2002                          
    International Symposium on Advanced Radio Technologies 
      http://www.its.bldrdoc.gov/meetings/art/index.html  
   --------------------------------------------------------




More information about the FRPythoneers mailing list