try: do sometingexcept:
os._exit(0)比如执行do someting 时有错误,我想再试两次,如果两次执行还是有错误,那就os._exit(0) 退出
2 回答

慕桂英3389331
TA贡献2036条经验 获得超8个赞
我找到方法了,分享出来
import os attempts = 0success = False while attempts < 3 and not success: try: do something success = True except: attempts += 1 if attempts==3: os._exit(0)

元芳怎么了
TA贡献1798条经验 获得超7个赞
呃,这样?
def retry_do(func, retry=None): try: func() except: if retry: retry() else: os._exit(0)def do_sth(): #do something retry_do(do_sth, retry_do(do_sth, retry_do(do_sth)))
添加回答
举报
0/150
提交
取消