[英]Loop unexpectantly stops after one iteration
我正在遍历一个长度为4的列表,但是在一次迭代之后它停止了。
print((data))
formatted_exec_dictionary_list = []
for entry in data:
print(entry)
try:
formatted_exec = {
'minute': self.validate_type_and_range(entry[0], 0, 59),
'hour': self.validate_type_and_range(entry[1], 0, 23),
'path': entry[2]
}
formatted_exec_dictionary_list.append(formatted_exec)
except IndexError as exception:
print(exception)
if self.logger:
self.logger.error("""
Could not successfully parse entry...
Exception: %s""", exception)
在代码段的最上方打印中,这是输出:
[[u'30', u'1', u'/bin/run_me_daily'], [u'45', u'*', u'/bin/run_me_hourly'],
[u'*', u'*', u'/bin/run_me_every_minute'],
[u'*', u'19', u'/bin/run_me_sixty_times']]
但是for循环包装的打印仅返回第一个条目,然后停止。
似乎没有异常,因为没有打印图像,并且程序的其余功能正常。 好像列表中的所有其余条目都被忽略了...
这很常见吗? 任何线索为什么会这样?
为了澄清起见,没有什么特别的事情发生在似乎抛出异常的循环中。 函数validate_type_and_range
打印预期数据,但仅打印一次迭代。
当我用一些字符串替换“ validate_type_and_range(...)”时,得到以下输出:
[[u'30', u'1', u'/bin/run_me_daily'], [u'45', u'*', u'/bin/run_me_hourly'], [u'*', u'*', u'/bin/run_me_every_minute'],
[u'*', u'19', u'/bin/run_me_sixty_times']]
[u'30', u'1', u'/bin/run_me_daily']
[u'45', u'*', u'/bin/run_me_hourly']
[u'*', u'*', u'/bin/run_me_every_minute']
[u'*', u'19', u'/bin/run_me_sixty_times']
我认为您的“ validate_type_and_range”中发生了某些情况
print((data))
formatted_exec_dictionary_list = []
for entry in data:
print(entry)
try:
formatted_exec = {
'minute': "foo",
'hour': "bar",
'path': entry[2]
}
formatted_exec_dictionary_list.append(formatted_exec)
except IndexError as exception:
print(exception)
if self.logger:
self.logger.error("""
Could not successfully parse entry...
Exception: %s""", exception)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.