是否可以在不使用 if/else 语句的情况下中断使用 execfile 函数调用的 Python 脚本的执行?我试过exit()
了,但它不允许main.py
完成。
# main.py
print "Main starting"
execfile("script.py")
print "This should print"
# script.py
print "Script starting"
a = False
if a == False:
# Sanity checks. Script should break here
# <insert magic command>
# I'd prefer not to put an "else" here and have to indent the rest of the code
print "this should not print"
# lots of lines below