try:dosometingexcept:os._exit(0)比如执行dosometing时有错误,我想再试两次,如果两次执行还是有错误,那就os._exit(0)退出
2 回答
慕标琳琳
TA贡献1830条经验 获得超9个赞
我找到方法了,分享出来importosattempts=0success=Falsewhileattempts<3andnotsuccess:try:dosomethingsuccess=Trueexcept:attempts+=1ifattempts==3:os._exit(0)
拉莫斯之舞
TA贡献1820条经验 获得超10个赞
呃,这样?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
提交
取消