except clause syntax question

Devin Jeanpierre jeanpierreda at gmail.com
Mon Jan 30 19:25:57 EST 2012

On Mon, Jan 30, 2012 at 7:00 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Mon, 30 Jan 2012 12:41:00 -0500, 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:
> Simplicity.

I agree with the snipped, but would also like to add that regardless
of why it might be so, tuples do appear to be the canonical type for
collections that need to be typechecked -- not just for except; it's a
consistent thing that if you're going to do something with "X, or a
bunch of X's", then it's either an X or a tuple of X's. For example,
string formatting with % works this way, as does isinstance(a, X).

-- Devin

More information about the Python-list mailing list