sys.exit versus raise SystemExit

Discussion in 'Python' started by Will McGugan, Jan 8, 2007.

  1. Will McGugan

    Will McGugan Guest

    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
     
    Will McGugan, Jan 8, 2007
    #1
    1. Advertising

  2. Will McGugan

    Guest

    , Jan 8, 2007
    #2
    1. Advertising

  3. Will McGugan

    Will McGugan Guest

    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
     
    Will McGugan, Jan 8, 2007
    #3
  4. Will McGugan

    Duncan Booth Guest

    Will McGugan <> wrote:

    > 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.
     
    Duncan Booth, Jan 8, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Bethard
    Replies:
    0
    Views:
    406
    Steven Bethard
    Jul 1, 2006
  2. GinTon

    sys.stderr.write and sys.exit

    GinTon, Nov 23, 2006, in forum: Python
    Replies:
    5
    Views:
    597
    Dennis Lee Bieber
    Nov 24, 2006
  3. Yujo
    Replies:
    2
    Views:
    439
    Gabriel Genellina
    Apr 10, 2007
  4. Replies:
    3
    Views:
    309
    Gabriel Genellina
    Jul 13, 2007
  5. Lloyd Zusman
    Replies:
    1
    Views:
    205
    Yukihiro Matsumoto
    Sep 28, 2004
Loading...

Share This Page