Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19654

Re: except clause syntax question

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed0.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <charles@declareSub.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'value,': 0.04; 'names.': 0.07; 'python': 0.08; 'exception.': 0.09; 'exceptions': 0.09; 'modulo': 0.09; 'am,': 0.12; 'exception': 0.12; 'library': 0.13; 'extensions': 0.15; '"serious': 0.16; 'block,': 0.16; 'denote': 0.16; 'exceptions.': 0.16; 'hint': 0.16; 'operator.': 0.16; 'semantically': 0.16; 'subject:syntax': 0.16; 'tuple,': 0.16; 'tuples,': 0.16; 'subject:question': 0.16; 'wrote:': 0.16; 'meant': 0.17; 'template': 0.19; 'jan': 0.19; 'seems': 0.19; 'maybe': 0.21; 'header:In-Reply-To:1': 0.22; 'statement': 0.23; 'operand': 0.23; 'defined': 0.24; 'string': 0.24; 'originally': 0.24; 'thanks.': 0.25; 'looks': 0.27; "i'm": 0.27; 'second': 0.29; 'fewer': 0.30; 'list"': 0.30; 'reflection,': 0.30; 'tuples': 0.30; 'x-mailer:apple mail (2.1084)': 0.30; 'least': 0.30; 'values': 0.32; 'supposed': 0.32; 'to:addr:python-list': 0.33; 'match': 0.33; 'rules': 0.33; 'wondering': 0.34; 'latter': 0.34; 'relaxed': 0.34; 'things': 0.35; 'similar': 0.36; 'opposed': 0.36; 'sequence': 0.36; 'skip:" 10': 0.36; 'charset:us-ascii': 0.36; 'but': 0.37; 'using': 0.37; 'why': 0.39; 'except': 0.39; 'sense': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'most': 0.60; 'unique': 0.60; 'type': 0.60; 'types': 0.61; 'more': 0.61; 'header:Message-Id:1': 0.62; '31,': 0.64; 'charles': 0.67; 'decision,': 0.67; 'strange': 0.68; 'collection': 0.68; '2012,': 0.84; 'marker': 0.84; 'markers': 0.84; 'received:64.191': 0.84; 'lists:': 0.91
Content-Type text/plain; charset=us-ascii
Mime-Version 1.0 (Apple Message framework v1084)
Subject Re: except clause syntax question
From Charles Yeomans <charles@declareSub.com>
In-Reply-To <jg8q29$ki5$1@speranza.aioe.org>
Date Tue, 31 Jan 2012 13:04:22 -0500
Content-Transfer-Encoding quoted-printable
References <mailman.5218.1327946109.27778.python-list@python.org> <jg8q29$ki5$1@speranza.aioe.org>
To Python <python-list@python.org>
X-Mailer Apple Mail (2.1084)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5257.1328033074.27778.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328033074 news.xs4all.nl 6902 [2001:888:2000:d::a6]:60209
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19654

Show key headers only | View raw


On Jan 31, 2012, at 8:24 AM, Mel Wilson wrote:

> Charles Yeomans wrote:
> 
>> To catch more than one exception type in an except block, one writes
>> 
>> except (A, B, C) as e:
>> 
>> I'm wondering why it was decided to match tuples, but not lists:
>> 
>> except [A, B, C] as e:
>> 
>> The latter makes more sense semantically to me -- "catch all exception
>> types in a list" as opposed to "catch this single thing composed of three
>> exception types".
> 
> On reflection, it seems to hint at a style that Python extensions were made 
> in.  (IIRC) the first operand in an `except` statement was originally just 
> an arbitrary marker to identify the exception.  Unique string values were 
> customary, although the Python library defined things with standard 
> exception names.  Using a string means that general exceptions weren't to be 
> collected in general sequences; `except "Serious Error"` was never meant to 
> catch `raise "r"`.  If only tuples were used for collections, it would 
> create havoc for fewer of any weirdos who had used strange markers of their 
> own devising.
> 
> It looks like tuples were chosen as the most "lightweight", or maybe least 
> intrusive, sequence type to require to denote a collection of exceptions.
> 
> You see a similar decision, with the opposite emphasis, with the string 
> modulo operator.  The second operand is supposed to be a tuple, but if the 
> template string needs only one value, then the rules are relaxed and any 
> single non-tuple value is used as-is.
> 

Compatilbility; that makes sense.  I came to python well after strings were used for exceptions.  Thanks.


Charles Yeomans

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

except clause syntax question Charles Yeomans <charles@declareSub.com> - 2012-01-30 12:41 -0500
  Re: except clause syntax question Mel Wilson <mwilson@the-wire.com> - 2012-01-30 14:15 -0500
  Re: except clause syntax question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-31 00:00 +0000
    Re: except clause syntax question Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-30 19:25 -0500
    Re: except clause syntax question Charles Yeomans <charles@declareSub.com> - 2012-01-31 08:57 -0500
      Re: except clause syntax question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-31 14:51 +0000
        Re: except clause syntax question Charles Yeomans <charles@declareSub.com> - 2012-01-31 11:23 -0500
        Re: except clause syntax question Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-31 11:38 -0500
        Re: except clause syntax question Charles Yeomans <charles@declaresub.com> - 2012-01-31 12:29 -0500
        Re: except clause syntax question Ethan Furman <ethan@stoneleaf.us> - 2012-01-31 08:56 -0800
    Re: except clause syntax question Terry Reedy <tjreedy@udel.edu> - 2012-01-31 19:12 -0500
    Re: except clause syntax question Charles Yeomans <charles@declareSub.com> - 2012-01-31 19:27 -0500
  Re: except clause syntax question Mel Wilson <mwilson@the-wire.com> - 2012-01-31 08:24 -0500
    Re: except clause syntax question Charles Yeomans <charles@declareSub.com> - 2012-01-31 13:04 -0500
  Re: except clause syntax question Duncan Booth <duncan.booth@invalid.invalid> - 2012-01-31 22:03 +0000
    Re: except clause syntax question Chris Angelico <rosuav@gmail.com> - 2012-02-01 11:53 +1100
      Re: except clause syntax question Mel Wilson <mwilson@the-wire.com> - 2012-01-31 23:39 -0500
    Re: except clause syntax question Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-31 18:09 -0700
    Re: except clause syntax question Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-31 18:12 -0700
    Re: except clause syntax question Chris Angelico <rosuav@gmail.com> - 2012-02-01 13:46 +1100

csiph-web