# 500G一行的超大文本文件,有分隔符{|}def myreadlines(f,newline): buf="" while True: while newline in buf: pos = buf.index(newline) yield buf[:pos] buf = buf[pos+len(newline):] chunk =f.read(4096*10) if not chunk: # 说明已经读到了文件结尾 yield buf break buf += chunkwith open("input.txt") as f: for line in myreadlines(f, "{|}"): print(line)复制代码