mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
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:
parent
893523e80a
commit
b940e113bf
295 changed files with 817 additions and 743 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue