以编程方式停止执行python脚本? [英] Programmatically stop execution of python script?

查看:42
本文介绍了以编程方式停止执行python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用命令在任何行停止执行 python 脚本?

Is it possible to stop execution of a python script at any line with a command?

喜欢

some code

quit() # quit at this point

some more code (that's not executed)

推荐答案

sys.exit() 会做你想做的事.

import sys
sys.exit("Error message")

这篇关于以编程方式停止执行python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆