Created
December 16, 2021 23:11
-
-
Save grubberr/3ca88a37975e3b2c095f3d598d8e57f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def iter_lines(gen): | |
buffer = "" | |
for chunk in gen: | |
buffer += chunk | |
while True: | |
pos = buffer.find('\n') | |
if pos <= -1: | |
break | |
yield buffer[:pos+1] | |
buffer = buffer[pos+1:] | |
if buffer: | |
yield buffer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment