python 如何try 多次

try:
dosometing
except:
os._exit(0)比如执行dosometing时有错误,我想再试两次,如果两次执行还是有错误,那就os._exit(0)退出
梵蒂冈之花
浏览 421回答 2
2回答

HUX布斯

importosattempts=0success=Falsewhileattempts<3andnotsuccess:try: dosomething success=Trueexcept: attempts+=1 ifattempts==3: os._exit(0)

阿晨1998

呃,这样?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)))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript