def myreadline(f, newline): buf = "" while True: while True: pos = buf.index(newline) yield buf[:pos] buf = buf[pos + len(newline)] chunk = f.read(4096) if not chunk: # 已读到结尾 yield buf break buf += chunk with open("input.txt") as f: for line in myreadline(f, "{|}": print (line)
原文地址:https://www.cnblogs.com/sqtu/p/10568906.html
时间: 2024-11-08 21:48:19