I usually do such things in C ++, but I use python to write a quick script, and I ran into a wall.
If I have a binary list (or something like python stores the result of "fread"). I can access individual bytes in it with: buffer [0], buffer [1], etc.
I need to change the bytes [8-11] to save the new 32-bit file size (read: there are already files there, I need to update it). In C ++, I would just get a pointer to a location and drop it to store an integer, but with python, I suddenly realized that I had no idea how to do this.
How can I update 4 bytes in my buffer in a specific place to store an integer value in python?
EDIT
I am going to add more because I cannot figure it out from the solutions (although I can see that they are on the right track).
First of all, I'm on python 2.4 (and cannot upgrade the servers of large corporations) - so that seems to be limiting my options. Sorry I didn’t mention this before, I didn’t know that it had so many functions.
Secondly, let's make it super simple.
Suppose I have a binary file named 'myfile.binary' with five-byte contents “4C53535353” in hexadecimal format - this is equivalent to the ascii representation for the letters “L and 4xS” in the file.
If I do this:
f = open('myfile.binary', 'rb')
contents = f.read(5)
the content should (from Sven Marnach’s answer) contain a five-byte immutable string.
Python 2.4, 4 S "" ? , [1-4], 32- "myint" 12345678910.