我在阅读函数式编程python时遇到问题。
def get_log_lines(log_file):
line = read_line(log_file)
while True:
try:
if complex_condition(line):
yield line
line = read_line(log_file)
except StopIteration:
raise
添加了一个try...except
语句来包围read_line
. 为什么不让read_line
抛出这样的StopIteration
异常:
def get_log_lines(log_file):
line = read_line(log_file)
while True:
if complex_condition(line):
yield line
line = read_line(log_file)