473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 11300

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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.