错误后从头开始重新启动脚本

时间:2015-02-07 21:46:45

标签: python python-3.x

我想做以下事情:

  1. 运行python脚本
  2. if error - 然后从脚本开头重新启动
  3. 我该怎么做?

1 个答案:

答案 0 :(得分:3)

您可以在try循环中放置except - else - while块来执行此操作

while True:
    try: # put your code below
        ...
        ...
    except: #Exception was raised, else will not be executed
        ...
    else: #Script succeeded without errors
        ...
        break