[Tutor] Halting execution
Ertl, John
john.ertl at fnmoc.navy.mil
Wed May 3 21:19:02 CEST 2006
For this case, just wanting to stop the code for testing, using a short
statement as the arg is not only OK it is an example in the doc.
exit( [arg])
Exit from Python. ...... In particular, sys.exit("some error message") is a
quick way to exit a program when an error occurs.
I agree I should be a bit more careful about giving examples that are quick
fixes as opposed to best practice.
John
-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of Hugo González Monteverde
Sent: Wednesday, May 03, 2006 12:05 PM
To: tutor at python.org
Subject: Re: [Tutor] Halting execution
It would be similar to Perl's die() commmand. But no, in Python the
argument is the error status of your script.
You'd have to do something like
def exitnow(arg):
print arg
#maybe sys has not been imported
import sys
sys.exit(1)
Hugo
Ertl, John wrote:
> Matthew,
>
> Not sure if ipython is different but have you tried sys.exit("stoping
now")
>
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list