Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19654
| Subject | Re: except clause syntax question |
|---|---|
| From | Charles Yeomans <charles@declareSub.com> |
| Date | 2012-01-31 13:04 -0500 |
| References | <mailman.5218.1327946109.27778.python-list@python.org> <jg8q29$ki5$1@speranza.aioe.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5257.1328033074.27778.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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