无限循环使用条件语句和可窥探的迭代?

时间:2016-03-25 18:22:53

标签: python python-2.7 while-loop iterator

我在使用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是否在样本中时,它会被捕获,因为它会在那里循环。 事情在哪里陷入困境?谢谢!

0 个答案:

没有答案