2019-02-15
阅读量:
1064
python 如何try 多次?
python 如何try 多次?
try:
do someting
except:
os._exit(0)
比如执行do someting 时有错误,我想再试两次,如果两次执行还是有错误,那就os._exit(0) 退出
答:举个例子
import os
attempts = 0
success = False
while attempts < 3 and not success:
try:
do something
success = True
except:
attempts += 1
if attempts==3:
os._exit(0)






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论