472,976 Members | 1,250 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,976 software developers and data experts.

sys.exit versus raise SystemExit

Hi,

Is there any difference between calling sys.exit() and raise SystemExit?
Should I prefer one over the other?

Regards,

Will McGugan
--
blog: http://www.willmcgugan.com
Jan 8 '07 #1
3 11223

Will McGugan wrote:
Hi,

Is there any difference between calling sys.exit() and raise SystemExit?
Should I prefer one over the other?

Regards,

Will McGugan
--
blog: http://www.willmcgugan.com
sys.exit() raises a SystemExit, see
http://docs.python.org/lib/module-sys.html

Jan 8 '07 #2
wi******@hotmail.com wrote:
>
sys.exit() raises a SystemExit, see
http://docs.python.org/lib/module-sys.html
Oh I know. I was just wondering if there was some sort of subtle 'best
practice' recommendation that I wasnt aware of for using sys.exit over
raising the exception manually. In the same way that 'open' is prefered
over 'file', even though they appear to do the same thing.

Will
--
blog: http://www.willmcgugan.com
Jan 8 '07 #3
Will McGugan <wi**@willNOmcguganSPAM.comwrote:
wi******@hotmail.com wrote:
>>
sys.exit() raises a SystemExit, see
http://docs.python.org/lib/module-sys.html
Oh I know. I was just wondering if there was some sort of subtle 'best
practice' recommendation that I wasnt aware of for using sys.exit over
raising the exception manually. In the same way that 'open' is prefered
over 'file', even though they appear to do the same thing.
'open' is preferred when you are opening a file, 'file' is preferred when
it is the type you want. That way you leave open the option to intercept
the 'open' action without interfering with tests against the type.

I guess in a similar way you should prefer the overridable sys.exit()
function rather than using the exception directly.
Jan 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Ivan Voras | last post by:
In a code such as: if len(sys.argv) < 2: print "I need arguments!" sys.exit(1) Is sys.exit() really a good choice? Is there something more elegant? (I tried return but it is valid only in a...
5
by: Simon Faulkner | last post by:
Does Python have a command that just stops all processing? Simon
0
by: gcash | last post by:
I've written an applet using Java3D for rendering, which works fine if you have Java3D installed, of course. What I want to do is try to import the Java3D libraries and bail with an error...
4
by: Bryan | last post by:
Quick question: Why does os._exit called from a Python Timer kill the whole process while sys.exit does not? On Suse. Bryan
1
by: Jia Lu | last post by:
Hi all. After using python shell (IDLE) for a while, I typed commands below to exit . But error ocurred. Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> raise...
3
by: GinTon | last post by:
Is the same use _sys.stderr.write('error message'); sys.exit(1)_ than _sys.exit('error message')_ ? Note: help(sys.exit) If the status is omitted or None, it defaults to zero (i.e., success)....
3
by: carl.dhalluin | last post by:
Hi, I am playing with the atexit module but I don't find a way to see the difference between a script calling sys.exit(<returncode>) and the interpreting arriving at the end of the source code...
0
by: Gary Robinson | last post by:
In Python 2.5.2, I notice that, in the interpreter or in a script, I can exit with: exit() But I don't see exit() mentioned as a built-in function; rather the Python Library Reference says we...
34
by: Drake | last post by:
I have a general question of Python style, or perhaps just good programming practice. My group is developing a medium-sized library of general-purpose Python functions, some of which do I/O....
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.