Python Forum
Hashing an address for binary file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hashing an address for binary file
#7
As far as I know (or found with minimal search efforts) the behavior of seeking past the end of a file is not defined. This simple test packs the first 32 bytes with zeros.
with open("test.bin", "wb") as file:
    file.seek(32)
    file.write(b"Where's Waldo")
Output:
Dump ................ ................ Where's Waldo
But this might just be the behavior for the compiler I am using or the platform I am running on. I have not found anything definitive that says this is what I should expect. And since I don't know this will always work, I am not going to depend on it ever working.

Either way I would never use the value returned by hash as a file offset. hash(2000) == 2000 and hash(2001) == 2001. 2000 requires at least 3 bytes of storage, so I cannot store 2000 and 2001 using your scheme. And what about this?
x = "one"
y = "two"
print(hash(x), hash(y), id(x), id(y))
Output:
6029220552427752314 -4114662839508124676 1827875350256 1827875262064
I don't think I can seek(-4114662839508124676), and I don't want to make a 6029220552427752317 byte file to store "one".
Reply


Messages In This Thread
Hashing an address for binary file - by Python_help - Nov-03-2021, 04:38 PM
RE: Hashing an address for binary file - by deanhystad - Nov-03-2021, 07:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in entering address of a file in input akbarza 0 728 Oct-18-2023, 08:16 AM
Last Post: akbarza
  How do I read and write a binary file in Python? blackears 6 7,783 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Read/Write binary file deanhystad 3 3,331 Feb-01-2021, 10:29 AM
Last Post: Larz60+
  Binary File Error SalsaBeanDip 1 1,816 Oct-12-2020, 09:13 PM
Last Post: bowlofred
  Convert file of hex strings to binary file medatib531 4 13,994 Oct-09-2020, 05:42 PM
Last Post: DeaD_EyE
  Binary File Read Aussie 6 8,718 Sep-03-2020, 03:57 AM
Last Post: deanhystad
  Binary file Aussie 12 4,731 Aug-31-2020, 09:20 PM
Last Post: Aussie
  python read binary file Pyguys 4 4,060 Jul-13-2020, 02:34 AM
Last Post: Pyguys
  Failure in writing binary text to file Gigux 7 3,950 Jul-04-2020, 08:41 AM
Last Post: Gigux
  search binary file and list all founded keyword offset Pyguys 4 2,891 Mar-17-2020, 06:46 AM
Last Post: Pyguys

Forum Jump:

User Panel Messages

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