如果我的標題有點不清楚,我很抱歉,我不知道如何更好地表達我的問題。我將給出一個快速的代碼片段來說明我正在嘗試做的事情:
for data_file in data_files:
analyze(data_file)
def analyze(data_file):
for _ in np.arange(n_steps):
foo(data_file)
do some other things
def foo(data_file):
do some things
if (value > 1):
do some things
double_return()
else:
continue doing other things
我希望該函式double_return()執行的操作是回傳到更大的回圈:
for data_file in data_files:
(而不是return,這將繼續到下一步for _ in n_steps)。但是,我不確定在這里使用什么命令并且無法找到它。
uj5u.com熱心網友回復:
foo()可以回傳True,如果它完成,或者False如果你想“早點離開”:
for data_file in data_files:
analyze(data_file)
def analyze(data_file):
for _ in np.arange(n_steps):
if not foo(data_file):
return
do some other things
def foo(data_file):
do some things
if (value > 1):
do some things
return False
else:
continue doing other things
return True
編輯:
為了使含義更清楚,您可以定義foo_completed=True, 和foo_not_completed=False, 并使用這些常量而不是 True/False。
uj5u.com熱心網友回復:
您可以做的是回傳一個truthy值(假設所有其他路由foo()都是 default return None)并對其進行測驗:
def analyze(data_file):
for _ in np.arange(n_steps):
if foo(data_file):
return
do some other things
def foo(data_file):
do some things
if (value > 1):
do some things
return True
else:
continue doing other things
for data_file in data_files:
analyze(data_file)
它相當模糊了含義,但它將以可測驗的方式作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/479428.html
