Python Forum
Save multiple Parts of Bytearray to File ? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Save multiple Parts of Bytearray to File ? (/thread-38918.html)



Save multiple Parts of Bytearray to File ? - lastyle - Dec-10-2022

Hi all.

i`ve got an fixed Bytearray which consist of a $40 Bytes FileHeader and $10 Bytes Packet Header followed by $2000 Bytes Raw data

From that Array i need to Extract the first Package ($2000 Bytes) Starting at $0050, save it and then extracht the next Pack at $2060, save, next Package at $4070 and so on until i reach the End of the Array.

I thought best way is to Copy the wanted data to a new array and save it from there and when finished grab new Data. Sadly i fail to code a working Function that Grabs the Data from the Source Array. Anybody here who can give me a hint how to start ?

Thanks for reading


RE: Save multiple Parts of Bytearray to File ? - Gribouillis - Dec-10-2022

You can loop with range
for k in range(50, len(array), 2010):
    chunk = array[k:k+2000]
    # do something with chunk