4 ms·
`iter` can be used to convert from a repeated function call with a sentinel to an iterator: for frame_stab, frame_org in zip(iter(stream_stab.read, None), it
by compressedgas 7y ago
`iter` can be used to convert from a repeated function call with a sentinel to an iterator:
for frame_stab, frame_org in zip(iter(stream_stab.read, None), iter(stream_org.read, None)):
...
This line replaces the first 12 lines of the loop in the example.
- BiteCode_dev 7y agoAlso a good example where 3.8 would be handy: while (frame_stab := stream_stab.read()) and (stream_org := stream_org.read()): iter() works with all stable versions of Python though, but it's a bit exotic. When I use it, I tend to make aliases to make it clearer because most Python devs don't know about it, let alone this alternative form. stab_frames = iter(stream_stab.read, None) org_frames = iter(stream_org.read, None) for frame_stab, frame_org in zip(stab_frames, org_frames):
- abhiTronix 7y agostab_frames = iter(stream_stab.read, None) org_frames = iter(stream_org.read, None) for frame_stab, frame_org in zip(stab_frames, org_frames): wow, I did'nt knew about this. Thanks for posting. I'm definetly adding this in the next release.