Czy można przerwać wykonywanie skryptu w języku Python wywołanego funkcją execfile bez użycia instrukcji if/else? Próbowałem już exit()
, ale to nie pozwala na zakończenie main.py
.Zatrzymaj wykonywanie skryptu wywoływanego przy użyciu 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
Dlaczego używasz execfile() i nie importować? – ephemient
Myślę, że execfile pozwala na większą elastyczność, gdy edytuję skrypty w osobnym oknie i wykonuję je w locie – JcMaco