Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.04; 'python3': 0.07; 'skip:l 60': 0.07; 'aliases': 0.09; 'modulo': 0.09; 'pgp': 0.09; 'try:': 0.09; 'python': 0.11; '(valueerror,': 0.16; '----- begin': 0.16; '-----end': 0.16; 'expect,': 0.16; 'from:addr:ian': 0.16; 'gnupg': 0.16; 'hash:': 0.16; 'parentheses:': 0.16; 'sha1': 0.16; 'skip:v 60': 0.16; 'syntaxerror:': 0.16; 'valueerror': 0.16; 'valueerror,': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'message-----': 0.19; 'skip:a 60': 0.19; '>>>': 0.22; 'example': 0.22; 'header:User-Agent:1': 0.23; 'integer': 0.24; 'pass': 0.26; 'signed': 0.27; 'header:In-Reply-To:1': 0.27; '"",': 0.31; "d'aprano": 0.31; 'division': 0.31; 'received:66.33': 0.31; 'received:66.33.216': 0.31; 'received:66.33.216.122': 0.31; 'received:dreamhost.com': 0.31; 'received:g.dreamhost.com': 0.31; 'received:hapkido.dreamhost.com': 0.31; 'skip:i 60': 0.31; 'skip:m 60': 0.31; 'steven': 0.31; 'file': 0.32; 'linux': 0.33; '(most': 0.33; 'received:66': 0.35; 'subject:with': 0.35; 'except': 0.35; 'but': 0.35; 'version:': 0.36; 'list': 0.37; 'to:addr:python- list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'catch': 0.60; 'ian': 0.60; 'skip:* 10': 0.61; 'more': 0.64; 'charset:windows-1252': 0.65; 'mar': 0.68; 'invalid': 0.68; '2014,': 0.84; 'subject:..': 0.84; 'received:192.168.0.4': 0.91 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=feete.org; h=message-id :date:from:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; s=feete.org; bh=Mm1pIlL CuYl7GOwtF0ILggbJRQ0=; b=bmLSQKhl9gwP9FEXp3D6vDPnLEk0hDZaDRtd8w4 rEanpFF966r30kSk3+N+SomvdI16NeQATndsZby4J3vkdtSm1LOdNPHm9x9ZXN1q H5ECB1ErCNhQ2Eq5pt8aVG/dHpEd7jGn2jzy1J5D5uBqLhk6fjkSkLwMKmIizsd0 TOe8= Date: Sat, 11 Apr 2015 15:20:13 +0100 From: Ian Foote User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: try..except with empty exceptions References: <64a75c32-e0ab-4ce0-9373-358c2669fe6e@googlegroups.com> <785010c0-6bcc-46d7-b7e0-0ed062fabbc7@googlegroups.com> <55287c0d$0$13000$c3e8da3$5496439d@news.astraweb.com> <5528c906$0$12994$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <5528c906$0$12994$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1428762375 news.xs4all.nl 2913 [2001:888:2000:d::a6]:48203 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88820 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 11/04/15 08:11, Steven D'Aprano wrote: > But with try...except, an empty exception list means to catch > *everything*, not nothing: >=20 > try: ... except a,b,c: # catches a, b, c >=20 > try: ... except a,b: # catches a, b This example is incorrect. In python3 it is a SyntaxError: Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> try: ... 1/0 ... except ValueError, ZeroDivisionError: File "", line 3 except ValueError, ZeroDivisionError: ^ SyntaxError: invalid syntax In python2 it aliases ValueError as ZeroDivisionError: Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> try: ... 1/0 ... except ValueError, ZeroDivisionError: ... pass ... Traceback (most recent call last): File "", line 2, in ZeroDivisionError: integer division or modulo by zero To get the behaviour you expect, you must use parentheses: >>> try: ... 1/0 ... except (ValueError, ZeroDivisionError): ... pass ... Regards, Ian F -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVKS2dAAoJEODsV4MF7PWznkAH/jidWhoJ//gsvBr0ByOOOEgc A+k8HqrkALfzrh3aEjJB3sq19oLfLcepQeFVUh77mJKOMCQdEeyJtqIz6tLc4RUa L/nXytHygXVTb5HIARGVkPD26gqAleSb9eZUfPeSEvRHy9UbFS7SMmOdkApheDX3 Vq8TOa8EchaYd+S89y9eepZAhGC7n2TNwrNgp36sbHoz/hYUxFNnugP0ow9FM0Wk MGKGh04c3Lao+6w7a0scz4YKKb8wTdYkyYwlJhEdg3q74+PwYJpkjcGucna745AZ XlAKlDCJ9LhPgMufuGdRNskJa4TF709ec5hG9itHu1lFKrjH1iJCEU9ntX6hInU=3D =3Dzi4K -----END PGP SIGNATURE-----