我在使用more_itertools peekable时获得了无限循环:
import more_itertools as it
temp = [line.rstrip('\n') for line in open('sample.txt')]
lines = it.peekable(temp)
try:
while True:
line = lines.next()
if DESCRIPTION in line:
description = line[len(DESCRIPTION) + 1:]
sample = lines.peek()
if CODE in sample:
pass
else:
continue
if(EOF in line):
break
except StopIteration:
pass
当我检查CODE是否在样本中时,它会被捕获,因为它会在那里循环。 事情在哪里陷入困境?谢谢!