title: Reading a binary file in Python into a struct
body: <p>How do I go about opening a binary data file in Python and reading back the values one <code>long</code>
  at a time, into a struct. I have something like this at the moment but I think this will keep overwriting <code>idList</code>, I want to append to it, so I end up with a tuple of all the <code>long</code> values in the file -</p>
  
  <pre><code>file = open(filename, "rb")
      try:
          bytes_read = file.read(struct.calcsize("=l"))
          while bytes_read:
              # Read 4 bytes(long integer)
              idList = struct.unpack("=l", bytes_read)
              bytes_read = file.read(struct.calcsize("=l"))
      finally:
          file.close()
  </code></pre>