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
#1
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 = f.read()
    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
Reply


Messages In This Thread
find the header location in a .bin file without reading the whole file at a time - by SANJIB - Mar-05-2021, 04:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  file open "file not found error" shanoger 8 1,185 Dec-14-2023, 08:03 AM
Last Post: shanoger
Sad problems with reading csv file. MassiJames 3 666 Nov-16-2023, 03:41 PM
Last Post: snippsat
  Need to replace a string with a file (HTML file) tester_V 1 790 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Reading a file name fron a folder on my desktop Fiona 4 936 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,601 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  How can I change the uuid name of a file to his original file? MaddoxMB 2 955 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  Formatting a date time string read from a csv file DosAtPython 5 1,336 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,130 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Cannot find py credentials file standenman 5 1,684 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 754 Feb-14-2023, 03:21 PM
Last Post: SouAmego22

Forum Jump:

User Panel Messages

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