Python Forum
Find offset of binary data in 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: Find offset of binary data in file (/thread-2247.html)



Find offset of binary data in file - sparkz_alot - Mar-01-2017

Going back to a thread about .wav files (https://python-forum.io/Thread-From-theory-to-practice) it was brought up that some files contain additional information above that provided for in the original format.  I thought I would try and account for the 'extras'.  I thought I would start by checking the file for the word "data" and found this solution on SO which seems to work in determining if it exists or not.  
The problem I can't seem to grasp is how to determine the offset (or where the text begins) in the file.  For instance, I know in my test file, the word "data" begins at dec 36, hex 0x24.  

I've searched the Google and can't seem to find anything.  So I'm wondering if anyone has any suggestions as to where I might start looking.

Thanks


RE: Find offset of binary data in file - zivoni - Mar-01-2017

I think that s.find(b'data') returns starting position of first occurence of b'data', so 36 with your data.


RE: Find offset of binary data in file - sparkz_alot - Mar-01-2017

Absolutely right!   Clap

Thank you very much.


RE: Find offset of binary data in file - Larz60+ - Mar-01-2017

position = file_handle.tell()