Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > What is the difference between 'except IOError as e:' and 'except

Reply
Thread Tools

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

 
 
Peng Yu
Guest
Posts: n/a
 
      11-18-2009
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
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      11-18-2009
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 04-15-2011 04:00 AM
FAQ 7.17 What's the difference between dynamic and lexical (static) scoping? Between local() and my()? PerlFAQ Server Perl Misc 0 01-06-2011 05:00 PM
Re: What is the difference between 'except IOError as e:' and 'except MRAB Python 0 11-18-2009 02:52 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
Exact difference between 'const char *' and 'char *', also diff between 'const' and 'static' Santa C Programming 1 07-17-2003 02:10 PM



Advertisments