May-29-2018, 08:12 AM
The "per line" operator works with binary files using '\n' as separator, so you can do something like:
Other option is to use a memory map.
with open('input.bin', 'rb') as fd: for line in fd: for sub_line in line.split(b'\r'): # Take into account any single '\r' if not sub_line: # If you want to deal also with zero length groups, thsi must be improved... continue # Do something with the lines passIf you can guarantee in the input format that splitting by '\n' is safe is a good way.
Other option is to use a memory map.