import sys
for i inrange(10):print(i)if i ==5:
sys.exit("Finish")
実行結果
012345
An exception has occurred, use %tb to see the full traceback.
SystemExit: Finish
終了コードとしては正常終了を示す「0」、異常終了を示す「1」をよく使うようです。
import sys
for i inrange(10):print(i)if i ==5:
sys.exit(0)
実行結果
012345
An exception has occurred, use %tb to see the full traceback.
SystemExit:0
import sys
for i inrange(10):print(i)if i ==5:
sys.exit(1)
実行結果
012345
An exception has occurred, use %tb to see the full traceback.
SystemExit:1
import sys
for i inrange(10):print(i)if i ==5:print("Error")
sys.exit(1)
実行結果
012345
Error
An exception has occurred, use %tb to see the full traceback.
SystemExit:1
コメント