What is the idiomatic way to iterate over a binary file?
Try: chunk_size = 4 * 1024 * 1024 # MB with open(‘large_file.dat’,’rb’) as f: for chunk in iter(lambda: f.read(chunk_size), b”): handle(chunk) iter needs a function with zero arguments. a plain f.read would read the whole file, since the size parameter is missing; f.read(1024) means call a function and pass its return value (data loaded from … Read more