ある条件下で早期に終了したいスクリプトがあります。
if not "id" in dir():
print "id not set, cannot continue"
# exit here!
# otherwise continue with the rest of the script...
print "alright..."
[ more code ]
Python インタラクティブ プロンプトを使用してこのスクリプトを実行しexecfile("foo.py")
、スクリプトを終了してインタラクティブ インタープリターに戻りたいと考えています。どうすればいいですか?を使用するsys.exit()
と、Python インタープリターは完全に終了します。