What is the difference between 'except IOError as e:' and 'except

Discussion in 'Python' started by Peng Yu, Nov 18, 2009.

  1. Peng Yu

    Peng Yu Guest

    I don't see any different between the following code in terms of
    output. Are they exactly the same ('as' v.s. ',')?

    try:
    raise IOError('IOError')
    except IOError as e:
    print e

    try:
    raise IOError('IOError')
    except IOError, e:
    print e
     
    Peng Yu, Nov 18, 2009
    #1
    1. Advertisements

  2. Re: What is the difference between 'except IOError as e:' and'except

    On Tue, 17 Nov 2009 20:28:16 -0600, Peng Yu wrote:

    > I don't see any different between the following code in terms of output.
    > Are they exactly the same ('as' v.s. ',')?
    >
    > try:
    > raise IOError('IOError')
    > except IOError as e:
    > print e


    This is the preferred syntax. It is used in Python 2.6 and better. It is
    a syntax error in Python 2.5 and older.


    > try:
    > raise IOError('IOError')
    > except IOError, e:
    > print e


    This is the obsolete syntax, used in Python 2.5 and older.


    --
    Steven
     
    Steven D'Aprano, Nov 18, 2009
    #2
    1. Advertisements

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. jakk
    Replies:
    4
    Views:
    13,975
  2. Santa
    Replies:
    1
    Views:
    1,460
    Mark A. Odell
    Jul 17, 2003
  3. John Salerno
    Replies:
    20
    Views:
    1,229
    John Salerno
    Aug 11, 2006
  4. arnuld
    Replies:
    33
    Views:
    1,555
  5. Fabio Z Tessitore

    who is simpler? try/except/else or try/except

    Fabio Z Tessitore, Aug 12, 2007, in forum: Python
    Replies:
    5
    Views:
    675
  6. David House

    try -> except -> else -> except?

    David House, Jul 6, 2009, in forum: Python
    Replies:
    2
    Views:
    566
    Bruno Desthuilliers
    Jul 6, 2009
  7. PerlFAQ Server
    Replies:
    0
    Views:
    571
    PerlFAQ Server
    Jan 6, 2011
  8. PerlFAQ Server
    Replies:
    0
    Views:
    496
    PerlFAQ Server
    Apr 15, 2011
Loading...