import re
def open_delimited(filename, delimiter, chunksize=1024, args, kwargs):
with open(filename, args, **kwargs) as infile:
remainder = ‘’
for chunk in iter(lambda: infile.read(chunksize), ‘’):
pieces = re.split(delimiter, remainder+chunk)
for piece in pieces[:-1]:
yield piece
remainder = pieces[-1]
if remainder:
yield remainder
for line in open_delimited("log.txt", delimiter='/'): print(repr(line))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)