Python Forum
find the header location in a .bin file without reading the whole file at a time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find the header location in a .bin file without reading the whole file at a time
The below code is okay to find the header locations in a .bin file. But I don't want to read whole file at a time. Because the header has different byte format. If I read the whole as a uint16, I will not be able to get those bytes(some are uint8 and uint32). What is the solution so that I can read the file to find the header location and then I can assign the datatype for the header for the information. Basically discard all data before the header and read the header(2bytes-2bytes[little endian]-2bytes[big endian]-1bytes-1byte-......) Thanks in advance!!!!

with open(filename, mode='rb') as f:
    b =
    np_data = np.frombuffer(b, dtype=np.uint16)
    findIndex = np.where(np_data == int("00000050", 16))
Larz60+ write Mar-05-2021, 04:21 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Also fixed indentation

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replace columns indexes reading a XSLX file Larry1888 2 268 Nov-18-2022, 10:16 PM
Last Post: Pedroski55
  Find (each) element from a list in a file tester_V 3 289 Nov-15-2022, 08:40 PM
Last Post: tester_V
  Where can I find Python training with reading, lecture, labs and assignments? davidorlow 2 199 Oct-20-2022, 10:46 AM
Last Post: rob101
Photo Making Zip file of a file and Directory Nasir 2 251 Oct-07-2022, 02:01 PM
Last Post: Nasir
  Changing file location azizrasul 6 277 Sep-28-2022, 01:01 AM
Last Post: azizrasul
  Need Help: Convert .pcl file to .pdf file ManuRaval 6 507 Sep-13-2022, 01:31 PM
Last Post: ManuRaval
  Failing reading a file and cannot exit it... tester_V 8 539 Aug-19-2022, 10:27 PM
Last Post: tester_V
  read a text file, find all integers, append to list oldtrafford 12 1,081 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  what will be the best way to find data in txt file? korenron 2 428 Jul-25-2022, 10:03 AM
Last Post: korenron
  find some word in text list file and a bit change to them RolanRoll 3 549 Jun-27-2022, 01:36 AM
Last Post: RolanRoll

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020