for
ループ内で次のパターンが必要になる場合があります。同じループ内で複数回実行される場合があります。
try:
# attempt to do something that may diversely fail
except Exception as e:
logging.error(e)
continue
今ではできないので、これを関数でラップする良い方法がわかりませんreturn continue
:
def attempt(x):
try:
raise random.choice((ValueError, IndexError, TypeError))
except Exception as e:
logging.error(e)
# continue # syntax error: continue not properly in loop
# return continue # invalid syntax
return None # this sort of works
私return None
ができたよりも:
a = attempt('to do something that may diversely fail')
if not a:
continue
しかし、それが正義だとは思いません。関数continue
内からforループを(または偽造して)伝えたいのですが。attempt