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. Advertising

  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. 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. jakk
    Replies:
    4
    Views:
    12,515
  2. John Salerno
    Replies:
    20
    Views:
    872
    John Salerno
    Aug 11, 2006
  3. Fabio Z Tessitore

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

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

    try -> except -> else -> except?

    David House, Jul 6, 2009, in forum: Python
    Replies:
    2
    Views:
    358
    Bruno Desthuilliers
    Jul 6, 2009
  5. MRAB
    Replies:
    0
    Views:
    861
Loading...

Share This Page