#生成器解决
def myreadlines(f,newline): #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 += chunk
#测试
with open("input.txt") as f:
for line in myreadlines(f,"{|}"):
print(line)