Pythonスクリプトの実行をプログラムで停止しますか? [重複] 質問する

Pythonスクリプトの実行をプログラムで停止しますか? [重複] 質問する

コマンドを使用して任意の行で Python スクリプトの実行を停止することは可能ですか?

のように

some code

quit() # quit at this point

some more code (that's not executed)

ベストアンサー1

sys.exit()まさにあなたが望む通りのことを行います。

import sys
sys.exit("Error message")

おすすめ記事