. , , , / ! - BACK, , , !
deque(), . ffile-, , ffile.
, -, , deque .
import cStringIO,collections
original_ffile=cStringIO.StringIO('''
> header, info, info
TEXT----------------------------------------------------------------
TEXT2-------------------------------------------
>header, info...
TEXT-----------------------------------------------------''')
def peaker(_iter,_buffer):
popleft=_buffer.popleft
while True:
while _buffer: yield popleft()
yield next(_iter)
buf=collections.deque()
push_back=buf.append
ffile=peaker(original_ffile,buf)
for line in ffile:
if line.startswith('>'):
print "found a header! %s"%line[:-1]
sequence = ""
for seqcheck in ffile:
if seqcheck.startswith('>'):
print "oops, we've gone too far, pushing back: %s"%seqcheck[:-1]
push_back(seqcheck)
break
sequence += seqcheck
:
found a header! > header, info, info
oops, we've gone too far, pushing back: >header, info...
found a header! >header, info...