
Nov. 15, 2020
7:19 p.m.
I don't think __bytes__ is necessarily a bad idea, but I want to point out a couple of things you may be unaware of. First, slicing a memoryview object creates a subview, so you can wrap your mmap object in a memoryview and then create slices for each partition, cluster run, etc. without wasting any memory (but not for fragmented files). Second, your iterator example works in Python as it stands if you substitute __iter__ for __bytes__ and writelines for write.