while True:
    newbuf = file.read(bufsize)
if not newbuf:
    yield buf
return
buf += newbuf
lines = buf.split(delimiter)
for line in lines[:-1]:
    yield line
buf = lines[-1]
How to read records terminated by custom separator from file in python?