SF patch 1631942 by Collin Winter:

(a) "except E, V" -> "except E as V"
(b) V is now limited to a simple name (local variable)
(c) V is now deleted at the end of the except block
This commit is contained in:
Guido van Rossum 2007-01-10 16:19:56 +00:00
parent 893523e80a
commit b940e113bf
295 changed files with 817 additions and 743 deletions

View file

@ -214,7 +214,7 @@ e.g. ::
>>> req = urllib2.Request('http://www.pretend_server.org')
>>> try: urllib2.urlopen(req)
>>> except URLError, e:
>>> except URLError as e:
>>> print e.reason
>>>
(4, 'getaddrinfo failed')
@ -326,7 +326,7 @@ attribute, it also has read, geturl, and info, methods. ::
>>> req = urllib2.Request('http://www.python.org/fish.html')
>>> try:
>>> urllib2.urlopen(req)
>>> except URLError, e:
>>> except URLError as e:
>>> print e.code
>>> print e.read()
>>>
@ -354,10 +354,10 @@ Number 1
req = Request(someurl)
try:
response = urlopen(req)
except HTTPError, e:
except HTTPError as e:
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
except URLError, e:
except URLError as e:
print 'We failed to reach a server.'
print 'Reason: ', e.reason
else:
@ -378,7 +378,7 @@ Number 2
req = Request(someurl)
try:
response = urlopen(req)
except URLError, e:
except URLError as e:
if hasattr(e, 'reason'):
print 'We failed to reach a server.'
print 'Reason: ', e.reason