try:dosometingexcept:os._exit(0)比如执行dosometing时有错误,我想再试两次,如果两次执行还是有错误,那就os._exit(0)退出
2 回答
绝地无双
TA贡献1946条经验 获得超4个赞
我找到方法了,分享出来importosattempts=0success=Falsewhileattempts<3andnotsuccess:try:dosomethingsuccess=Trueexcept:attempts+=1ifattempts==3:os._exit(0)
千万里不及你
TA贡献1784条经验 获得超9个赞
呃,这样?defretry_do(func,retry=None):try:func()except:ifretry:retry()else:os._exit(0)defdo_sth():#dosomethingretry_do(do_sth,retry_do(do_sth,retry_do(do_sth)))
添加回答
举报
0/150
提交
取消