Possible Duplicate:
reading integers from binary file in python
I’ve read the solution to a similar problem here: convert a string of bytes into an int (python) but I’m not quite sure how to repurpose it for my needs.
I have a .bin file which is just a sequence of bytes. Every set of 4 bytes represents a 32-bit number. I am trying to use the struct module as described in that linked question to convert every set of 4 bytes to an integer and print them to a new file. How can I achieve this?
Thanks for the help.
You might want to read Read ints from file in python
It is even more straightforward from that question.
I have not checked the following code but something along the spirit of
should do the trick, if you want to record the ints as readable integers in another file.