Re: except clause syntax question

2012-01-31 Thread Mel Wilson
Chris Angelico wrote: > On Wed, Feb 1, 2012 at 9:03 AM, Duncan Booth > wrote: >> Abitrarily nested tuples of exceptions cannot contain loops so the code >> simply needs to walk through the tuples until it finds a match. > > Is this absolutely guaranteed? The C API for CPython provides: > (Py2) h

Re: except clause syntax question

2012-01-31 Thread Chris Angelico
On Wed, Feb 1, 2012 at 12:12 PM, Ian Kelly wrote: > Incidentally, I *think* that any correctly written C code attempting > to nest a tuple inside itself would make the reference count of the > tuple be at least 2 at the time of the call, and so it would fail. Good, nice that that's certain :) Mi

Re: except clause syntax question

2012-01-31 Thread Ian Kelly
On Tue, Jan 31, 2012 at 6:09 PM, Ian Kelly wrote: > On Tue, Jan 31, 2012 at 5:53 PM, Chris Angelico wrote: >> On Wed, Feb 1, 2012 at 9:03 AM, Duncan Booth >> wrote: >>> Abitrarily nested tuples of exceptions cannot contain loops so the code >>> simply needs to walk through the tuples until it fi

Re: except clause syntax question

2012-01-31 Thread Ian Kelly
On Tue, Jan 31, 2012 at 5:53 PM, Chris Angelico wrote: > On Wed, Feb 1, 2012 at 9:03 AM, Duncan Booth > wrote: >> Abitrarily nested tuples of exceptions cannot contain loops so the code >> simply needs to walk through the tuples until it finds a match. > > Is this absolutely guaranteed? The C API

Re: except clause syntax question

2012-01-31 Thread Chris Angelico
On Wed, Feb 1, 2012 at 9:03 AM, Duncan Booth wrote: > Abitrarily nested tuples of exceptions cannot contain loops so the code > simply needs to walk through the tuples until it finds a match. Is this absolutely guaranteed? The C API for CPython provides: (Py2) http://docs.python.org/c-api/tuple.h

Re: except clause syntax question

2012-01-31 Thread Charles Yeomans
On Jan 31, 2012, at 7:12 PM, Terry Reedy wrote: > On 1/31/2012 8:57 AM, Charles Yeomans wrote: > >> In any case, though I appreciate your attempt at a post hoc justification, > > I was hoping for a positive explanation. > > I think the best you are going to get is that Python somewhat consisten

Re: except clause syntax question

2012-01-31 Thread Terry Reedy
On 1/31/2012 8:57 AM, Charles Yeomans wrote: In any case, though I appreciate your attempt at a post hoc justification, > I was hoping for a positive explanation. I think the best you are going to get is that Python somewhat consistently*, for both practical and historical reasons#, uses tupl

Re: except clause syntax question

2012-01-31 Thread Duncan Booth
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 >

Re: except clause syntax question

2012-01-31 Thread Charles Yeomans
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

Re: except clause syntax question

2012-01-31 Thread Ethan Furman
Charles Yeomans wrote: On Jan 31, 2012, at 9:51 AM, Steven D'Aprano wrote: On Tue, 31 Jan 2012 08:57:31 -0500, Charles Yeomans wrote: I don't think of a tuple as a container, and I don't think it a misunderstanding on my part to think this. >> Well, it is a misunderstanding, because tuples A

Re: except clause syntax question

2012-01-31 Thread Charles Yeomans
On Jan 31, 2012, at 11:38 AM, Devin Jeanpierre wrote: > On Tue, Jan 31, 2012 at 11:23 AM, Charles Yeomans > wrote: >> >> On Jan 31, 2012, at 9:51 AM, Steven D'Aprano wrote: >> >>> On Tue, 31 Jan 2012 08:57:31 -0500, Charles Yeomans wrote: >>> I don't think of a tuple as a container, and

Re: except clause syntax question

2012-01-31 Thread Devin Jeanpierre
On Tue, Jan 31, 2012 at 11:23 AM, Charles Yeomans wrote: > > On Jan 31, 2012, at 9:51 AM, Steven D'Aprano wrote: > >> On Tue, 31 Jan 2012 08:57:31 -0500, Charles Yeomans wrote: >> >>> I don't think of a tuple as a container, and I don't think it a >>> misunderstanding on my part to think this. >>

Re: except clause syntax question

2012-01-31 Thread Charles Yeomans
On Jan 31, 2012, at 9:51 AM, Steven D'Aprano wrote: > On Tue, 31 Jan 2012 08:57:31 -0500, Charles Yeomans wrote: > >> I don't think of a tuple as a container, and I don't think it a >> misunderstanding on my part to think this. > > Well, it is a misunderstanding, because tuples ARE containers.

Re: except clause syntax question

2012-01-31 Thread Steven D'Aprano
On Tue, 31 Jan 2012 08:57:31 -0500, Charles Yeomans wrote: > I don't think of a tuple as a container, and I don't think it a > misunderstanding on my part to think this. Well, it is a misunderstanding, because tuples ARE containers. You might as well say "I don't think of boxes as containers". W

Re: except clause syntax question

2012-01-31 Thread Charles Yeomans
On Jan 30, 2012, at 7:00 PM, Steven D'Aprano 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: >> >>

Re: except clause syntax question

2012-01-31 Thread Mel Wilson
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 >

Re: except clause syntax question

2012-01-30 Thread Devin Jeanpierre
On Mon, Jan 30, 2012 at 7:00 PM, Steven D'Aprano 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: >> >> e

Re: except clause syntax question

2012-01-30 Thread Steven D'Aprano
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. If you also allow lists, the

Re: except clause syntax question

2012-01-30 Thread Mel Wilson
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 >

Re: except clause syntax question

2012-01-30 Thread Charles Yeomans
On Jan 30, 2012, at 12:56 PM, Aaron wrote: > On 01/30/2012 06:41 PM, 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: >

Re: except clause syntax question

2012-01-30 Thread Aaron
On 01/30/2012 06:41 PM, 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 excep

except clause syntax question

2012-01-30 Thread Charles Yeomans
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