简体   繁体   English

如何退出python execfile()而没有退出整个脚本

[英]how to exit python execfile() with out exiting whole script

I have a code which runs mutile python codes such as below: 我有一个运行mutile python代码的代码,如下所示:

execfile("1.py")
execfile("2.py")
execfile("3.py")

however occasionally one of the above codes as an error, i put exit('error') in the code to cancell if there is an error. 但是偶尔会将上述代码中的一个作为错误,如果出现错误,我会在代码中输出exit('error')来取消。 However i want the rest of the code to run and exit('error') exits the whole code, not just the execfile. 但是我希望其余代码运行并exit('error')退出整个代码,而不仅仅是execfile。 How do i get the execfile to stop but the others to keep running? 如何让execfile停止但其他人继续运行?

The part of 1.py with exit() is: 带有exit()的1.py部分是:

try :
    Ntot=10000
    x,y,s=myMCMC2D(Ntot,0.78,0.63,1,1)
except :
    exit('error')
try:
    execfile('1.py')
except SystemExit:
    print "1.py exited"

Exit is an exception which can be caught. 退出是一个可以捕获的例外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM