Nov-03-2021, 07:46 PM
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.
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?
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".