from my_script import main
restart = True
while restart:
try:
main()
# This line will allow the script to end if main returns. Leave it out
# if you want main to get restart even when it returns with no errors.
restart = False
except Exception as e:
print("An error in main: ")
print(e.message)
print("Restarting main...")
这要求您的脚本my_script.py在本例中设置如下:
def foo():
raise ValueError("An error in foo")
def main():
print("The staring point for my script")
foo()
if __name__ == "__main__":
main()
你想要这样的东西:
这要求您的脚本
my_script.py
在本例中设置如下:相关问题 更多 >
编程相关推荐