python try可以使用多次吗?,pythontry可以使用,try: do s
python try可以使用多次吗?,pythontry可以使用,try: do s
try: do sometingexcept: os._exit(0)
比如执行do someting 时有错误,我想再试两次,如果两次执行还是有错误,那就os._exit(0) 退出
我找到方法了,分享出来
import osattempts = 0success = Falsewhile attempts < 3 and not success: try:do somethingsuccess = True except:attempts += 1if attempts==3: os._exit(0)
呃,这样?
def retry_do(func, retry=None): try: func() except: if retry: retry() else: os._exit(0)def do_sth(): #do somethingretry_do(do_sth, retry_do(do_sth, retry_do(do_sth)))
推荐使用retrying这个packege,不要脸地推一下我自己写的介绍。
编橙之家文章,
相关内容
- Python类 对象 函数后面的参数问题 学到后面更难学怎么
- Python pyqt能直接拖控件的开发界面程序吗?,pythonpyqt,在
- Python方法sax解析多个子节点xml格式如何处理,pythonsax
- python [:]相关应用大牛们可以详细的说说吗,python大牛
- python api中的动态参数的原理是什么?如何生成以及服务
- Python3当字符串中包含空格符时不查找却重建是为什么,
- Python requests获取网页源码报未能解码问题,pythonreques
- scrapy爬取list中所有项,只爬一个就结束了什么原因,s
- 求问关于vim的问题,syntastic插件中文保存报错误,vimsy
- pycharm支持同时运行最多几个程序,pycharm运行程序,pyc
评论关闭