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
diff --git a/Doc/howto/urllib2.rst b/Doc/howto/urllib2.rst
index 69ce508..858c9b1 100644
--- a/Doc/howto/urllib2.rst
+++ b/Doc/howto/urllib2.rst
@@ -214,7 +214,7 @@
 
     >>> 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 @@
     >>> 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 @@
     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 @@
     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
diff --git a/Doc/lib/email-unpack.py b/Doc/lib/email-unpack.py
index fb03e58..e596b98 100644
--- a/Doc/lib/email-unpack.py
+++ b/Doc/lib/email-unpack.py
@@ -35,7 +35,7 @@
 
     try:
         os.mkdir(opts.directory)
-    except OSError, e:
+    except OSError as e:
         # Ignore directory exists error
         if e.errno != errno.EEXIST:
             raise
diff --git a/Doc/lib/libcsv.tex b/Doc/lib/libcsv.tex
index e965e31..b87bc9d 100644
--- a/Doc/lib/libcsv.tex
+++ b/Doc/lib/libcsv.tex
@@ -426,7 +426,7 @@
 try:
     for row in reader:
         print row
-except csv.Error, e:
+except csv.Error as e:
     sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
 \end{verbatim}
 
diff --git a/Doc/lib/libgetopt.tex b/Doc/lib/libgetopt.tex
index b38fcd8..7930acd 100644
--- a/Doc/lib/libgetopt.tex
+++ b/Doc/lib/libgetopt.tex
@@ -126,7 +126,7 @@
 def main():
     try:
         opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
-    except getopt.GetoptError, err:
+    except getopt.GetoptError as err:
         # print help information and exit:
         print str(err) # will print something like "option -a not recognized"
         usage()
diff --git a/Doc/lib/libshutil.tex b/Doc/lib/libshutil.tex
index 449d741..3037e0b 100644
--- a/Doc/lib/libshutil.tex
+++ b/Doc/lib/libshutil.tex
@@ -144,6 +144,6 @@
                 copytree(srcname, dstname, symlinks)
             else:
                 copy2(srcname, dstname)
-        except (IOError, os.error), why:
+        except (IOError, os.error) as why:
             print "Can't copy %s to %s: %s" % (`srcname`, `dstname`, str(why))
 \end{verbatim}
diff --git a/Doc/lib/libsocket.tex b/Doc/lib/libsocket.tex
index f20c56c..69877d3 100644
--- a/Doc/lib/libsocket.tex
+++ b/Doc/lib/libsocket.tex
@@ -813,13 +813,13 @@
     af, socktype, proto, canonname, sa = res
     try:
 	s = socket.socket(af, socktype, proto)
-    except socket.error, msg:
+    except socket.error as msg:
 	s = None
 	continue
     try:
 	s.bind(sa)
 	s.listen(1)
-    except socket.error, msg:
+    except socket.error as msg:
 	s.close()
 	s = None
 	continue
@@ -848,12 +848,12 @@
     af, socktype, proto, canonname, sa = res
     try:
 	s = socket.socket(af, socktype, proto)
-    except socket.error, msg:
+    except socket.error as msg:
 	s = None
 	continue
     try:
 	s.connect(sa)
-    except socket.error, msg:
+    except socket.error as msg:
 	s.close()
 	s = None
 	continue
diff --git a/Doc/lib/libsubprocess.tex b/Doc/lib/libsubprocess.tex
index f639710..cb30974 100644
--- a/Doc/lib/libsubprocess.tex
+++ b/Doc/lib/libsubprocess.tex
@@ -284,7 +284,7 @@
         print >>sys.stderr, "Child was terminated by signal", -retcode
     else:
         print >>sys.stderr, "Child returned", retcode
-except OSError, e:
+except OSError as e:
     print >>sys.stderr, "Execution failed:", e
 \end{verbatim}
 
diff --git a/Doc/lib/libxdrlib.tex b/Doc/lib/libxdrlib.tex
index d0863d9..56474b7 100644
--- a/Doc/lib/libxdrlib.tex
+++ b/Doc/lib/libxdrlib.tex
@@ -246,6 +246,6 @@
 p = xdrlib.Packer()
 try:
     p.pack_double(8.01)
-except xdrlib.ConversionError, instance:
+except xdrlib.ConversionError as instance:
     print 'packing the double failed:', instance.msg
 \end{verbatim}
diff --git a/Doc/lib/libxmlrpclib.tex b/Doc/lib/libxmlrpclib.tex
index c870d26..7af9e76 100644
--- a/Doc/lib/libxmlrpclib.tex
+++ b/Doc/lib/libxmlrpclib.tex
@@ -358,7 +358,7 @@
 
 try:
     print server.examples.getStateName(41)
-except Error, v:
+except Error as v:
     print "ERROR", v
 \end{verbatim}
 
diff --git a/Doc/lib/sqlite3/complete_statement.py b/Doc/lib/sqlite3/complete_statement.py
index 22525e3..76ea7f6 100644
--- a/Doc/lib/sqlite3/complete_statement.py
+++ b/Doc/lib/sqlite3/complete_statement.py
@@ -23,7 +23,7 @@
 
             if buffer.lstrip().upper().startswith("SELECT"):
                 print cur.fetchall()
-        except sqlite3.Error, e:
+        except sqlite3.Error as e:
             print "An error occurred:", e.args[0]
         buffer = ""
 
diff --git a/Doc/tools/findcsyms b/Doc/tools/findcsyms
index ac9b754..d68c3ce 100755
--- a/Doc/tools/findcsyms
+++ b/Doc/tools/findcsyms
@@ -127,7 +127,7 @@
                 print_list(undocumented, "Undocumented symbols")
         else:
             print_list(L)
-    except IOError, e:
+    except IOError as e:
         if e.errno != errno.EPIPE:
             raise
 
diff --git a/Doc/tools/listmodules b/Doc/tools/listmodules
index 03e7b5d..8469972 100755
--- a/Doc/tools/listmodules
+++ b/Doc/tools/listmodules
@@ -53,7 +53,7 @@
         opts, args = getopt.getopt(
             args, "abchi:",
             ["annotate", "built-in", "categorize", "help", "ignore-from="])
-    except getopt.error, msg:
+    except getopt.error as msg:
         sys.stdout = sys.stderr
         print msg
         print
diff --git a/Doc/tools/mkhowto b/Doc/tools/mkhowto
index 21cd6fb..02a215d 100755
--- a/Doc/tools/mkhowto
+++ b/Doc/tools/mkhowto
@@ -599,7 +599,7 @@
     options = Options()
     try:
         args = options.parse(sys.argv[1:])
-    except getopt.error, msg:
+    except getopt.error as msg:
         error(options, msg)
     if not args:
         # attempt to locate single .tex file in current directory:
diff --git a/Doc/tools/mksourcepkg b/Doc/tools/mksourcepkg
index 4b21f77..7d5bd73 100755
--- a/Doc/tools/mksourcepkg
+++ b/Doc/tools/mksourcepkg
@@ -45,7 +45,7 @@
           opts, args = getopt.getopt(sys.argv[1:], "Aabgtzq",
                                      ["all", "bzip2", "gzip", "tools", "zip",
                                       "quiet", "anonymous"])
-     except getopt.error, e:
+     except getopt.error as e:
           usage(warning=str(e))
           sys.exit(2)
      if len(args) not in (1, 2):
diff --git a/Doc/tools/prechm.py b/Doc/tools/prechm.py
index 57a43fd..db1f965 100644
--- a/Doc/tools/prechm.py
+++ b/Doc/tools/prechm.py
@@ -448,7 +448,7 @@
 def openfile(file):
     try:
         p = open(file, "w")
-    except IOError, msg:
+    except IOError as msg:
         print file, ":", msg
         sys.exit(1)
     return p
@@ -466,7 +466,7 @@
 
     try:
         optlist, args = getopt.getopt(args, 'ckpv:')
-    except getopt.error, msg:
+    except getopt.error as msg:
         print msg
         usage()
 
diff --git a/Doc/tools/sgmlconv/docfixer.py b/Doc/tools/sgmlconv/docfixer.py
index 81519ee..961e3b8 100755
--- a/Doc/tools/sgmlconv/docfixer.py
+++ b/Doc/tools/sgmlconv/docfixer.py
@@ -1039,7 +1039,8 @@
     #
     try:
         write_esis(fragment, ofp, knownempty)
-    except IOError, (err, msg):
+    except IOError as e:
+        (err, msg) = e
         # Ignore EPIPE; it just means that whoever we're writing to stopped
         # reading.  The rest of the output would be ignored.  All other errors
         # should still be reported,
diff --git a/Doc/tools/sgmlconv/esis2sgml.py b/Doc/tools/sgmlconv/esis2sgml.py
index b6f9a44..81294d1 100755
--- a/Doc/tools/sgmlconv/esis2sgml.py
+++ b/Doc/tools/sgmlconv/esis2sgml.py
@@ -255,7 +255,8 @@
         if xml and xmldecl:
             opf.write('<?xml version="1.0" encoding="iso8859-1"?>\n')
         convert(ifp, ofp, xml=xml, autoclose=autoclose, verbatims=verbatims)
-    except IOError, (err, msg):
+    except IOError as e:
+        (err, msg) = e
         if err != errno.EPIPE:
             raise
 
diff --git a/Doc/tools/sgmlconv/esistools.py b/Doc/tools/sgmlconv/esistools.py
index 833fea1..6dc5eaa 100644
--- a/Doc/tools/sgmlconv/esistools.py
+++ b/Doc/tools/sgmlconv/esistools.py
@@ -139,7 +139,7 @@
     def _get_token(self, fp):
         try:
             line = fp.readline()
-        except IOError, e:
+        except IOError as e:
             e = SAXException("I/O error reading input stream", e)
             self.getErrorHandler().fatalError(e)
             return
diff --git a/Doc/tools/sgmlconv/latex2esis.py b/Doc/tools/sgmlconv/latex2esis.py
index 643ef2c..cbc9828 100755
--- a/Doc/tools/sgmlconv/latex2esis.py
+++ b/Doc/tools/sgmlconv/latex2esis.py
@@ -397,7 +397,8 @@
     c = Conversion(ifp, ofp, table)
     try:
         c.convert()
-    except IOError, (err, msg):
+    except IOError as e:
+        (err, msg) = e
         if err != errno.EPIPE:
             raise
 
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex
index 4b6b93f..3ecc57f 100644
--- a/Doc/tut/tut.tex
+++ b/Doc/tut/tut.tex
@@ -3480,8 +3480,9 @@
     f = open('myfile.txt')
     s = f.readline()
     i = int(s.strip())
-except IOError, (errno, strerror):
-    print "I/O error(%s): %s" % (errno, strerror)
+except IOError as e:
+    (errno, strerror) = e
+    print "I/O error(%s): %s" % (e.errno, e.strerror)
 except ValueError:
     print "Could not convert data to an integer."
 except:
@@ -3530,7 +3531,7 @@
 \begin{verbatim}
 >>> try:
 ...    raise Exception('spam', 'eggs')
-... except Exception, inst:
+... except Exception as inst:
 ...    print type(inst)     # the exception instance
 ...    print inst.args      # arguments stored in .args
 ...    print inst           # __str__ allows args to printed directly
@@ -3559,7 +3560,7 @@
 ... 
 >>> try:
 ...     this_fails()
-... except ZeroDivisionError, detail:
+... except ZeroDivisionError as detail:
 ...     print 'Handling run-time error:', detail
 ... 
 Handling run-time error: integer division or modulo by zero
@@ -3619,7 +3620,7 @@
 ... 
 >>> try:
 ...     raise MyError(2*2)
-... except MyError, e:
+... except MyError as e:
 ...     print 'My exception occurred, value:', e.value
 ... 
 My exception occurred, value: 4