是否有可能打破Python腳本中調用該函數的execfile執行不使用if/else語句?我試過exit()
,但它不允許main.py
完成。停止執行調用的execfile
# 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
你爲什麼要使用的execfile(),而不是導入? – ephemient 2009-06-22 18:04:48
我認爲當我在一個單獨的窗口中編輯腳本並執行它們時,execfile允許更大的靈活性 – JcMaco 2009-06-22 18:09:40