Python循环-AttributeError:';非类型';对象没有属性';执行';
我正在使用Python循环-AttributeError:';非类型';对象没有属性';执行';,python,Python,我正在使用while循环执行一些代码: while (totalIter > 0): totalIter = totalIter - 1 route_data = yield Runner.execute(endpoint, endpoint.config, command, send_data) 其中,Runner作为从prov.runners.base导入Runner yield语句第一次运行良好,但在第二次执行循环时,它抛出以下错误 AttributeError:“
while
循环执行一些代码:
while (totalIter > 0):
totalIter = totalIter - 1
route_data = yield Runner.execute(endpoint, endpoint.config, command, send_data)
其中,Runner
作为从prov.runners.base导入Runner
yield
语句第一次运行良好,但在第二次执行循环时,它抛出以下错误
AttributeError:“非类型”对象没有属性“执行”
表示Runner
已变为None
我试过做一些事情,但没有用
import prov.runners.base
while (totalIter > 0):
totalIter = totalIter - 1
reload(prov.runners.base.Runner)
route_data = yield prov.runners.base.Runner.execute(endpoint, endpoint.config, command, send_data)
这会产生错误:
AttributeError:“非类型”对象没有属性“runners”
第二次执行时,指示prov
为None
仅尝试重新加载Runner
,但python给出了错误,即reload需要将模块作为参数。
这个问题是否与模块加载或其他问题有关?与您的问题无关,但是否有任何特殊原因导致您使用while循环进行迭代,并手动递减,而不是对范围内的(totalIter)执行
:
?如果将route\u data=yield…
替换为print(Runner)
?python新手,如果改为for循环,效果会更好:)@Jean Françoisfare工作良好,打印
的次数与循环执行次数相同。似乎是yield
导致了问题。好的,然后尝试生成一些无关的内容。