Python Forum

Full Version: Python offset to length write in a File
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have these two values in a tuple
(offset, length)

The 'offset' is basically a pointer here.I want to write the content of the 'offset' up to the 'length' (contains number of bytes) in a FILE.

What is the best way to do that in Python ? How to implement this ?
f.write(data[offset:length])

If that doesn't help, then you'll need to give more info on what you're doing, such as a small snippet of code we can look at. Otherwise we're just guessing.
To be more precise...I am reading an Object (text,image,mp3,pdf,exe etc.) into few chunks of bytes.
Say, a 100 bytes image is being read into small chunks of 10 bytes (10 chunks).

Each time the object is being read, the Offset upto which it is being read is returned. Plus, the number of bytes read (i.e. lenght) for ex. 10 bytes here.

Now, I have these two values in a Tuple, the Offset pointer and the length.

I want to dump that into a file i.e. the each 10 bytes that is being read is going to be dumped in the File as well.

How to implement that ??
basic_learner Wrote:Each time the object is being read, the Offset upto which it is being read is returned. Plus, the number of bytes read (i.e. lenght) for ex. 10 bytes here.
Normally when one reads a chunk of bytes, the bytes just read are returned. This is what you need if you want to write them in another file. Don't you have these 10 bytes?