Re: idiomatic way to collect and report multiple exceptions?

2010-05-10 Thread Jean-Michel Pichavant
Ben Cohen wrote: Apologies for the TABs -- I wrote that example for demonstration purposes in my mail client -- I'll copy and paste from a real code editor in the future. Ben There's nothing to apologies for. Be wary of those trying to get you out of the right path, they will lie to you

Re: idiomatic way to collect and report multiple exceptions?

2010-05-08 Thread Ben Cohen
I've condensed the advice from this thread into this. import sys import traceback class ExceptionList(object): def __init__(self, msg, errors=None, *args): self.errortb = errors or [] super(ExceptionList, self).__init__(msg, *args) def __str__(self): Print a pretty

Re: idiomatic way to collect and report multiple exceptions?

2010-05-07 Thread Steven D'Aprano
On Thu, 06 May 2010 21:56:10 -0700, Chris Rebert wrote: [...] Output from example: Traceback (most recent call last): File tmp.py, line 35, in module multiple_err.do_raise() File tmp.py, line 25, in do_raise raise self __main__.MultipleValidationErrors: See the following

Re: idiomatic way to collect and report multiple exceptions?

2010-05-07 Thread Aahz
In article mailman.2715.1273204222.23598.python-l...@python.org, Ben Cohen nco...@ucsd.edu wrote: eg -- I'd like to do something like this: errors = [] for item in data: try: process(item) except ValidationError as e: errors.append(e) raise

Re: idiomatic way to collect and report multiple exceptions?

2010-05-07 Thread Ben Cohen
Many thanks for the excellent example!! You rock! Ben On May 6, 2010, at 10:56 PM, Chris Rebert wrote: On Thu, May 6, 2010 at 8:50 PM, Ben Cohen nco...@ucsd.edu wrote: Is there a pythonic way to collect and display multiple exceptions at the same time? For example let's say you're

Re: idiomatic way to collect and report multiple exceptions?

2010-05-07 Thread Steven D'Aprano
On Fri, 07 May 2010 14:28:05 -0700, Aahz wrote: In article mailman.2715.1273204222.23598.python-l...@python.org, Ben Cohen nco...@ucsd.edu wrote: eg -- I'd like to do something like this: errors = [] for item in data: try: process(item) except ValidationError as e:

Re: idiomatic way to collect and report multiple exceptions?

2010-05-07 Thread Chris Rebert
On May 6, 2010, at 10:56 PM, Chris Rebert wrote: On Thu, May 6, 2010 at 8:50 PM, Ben Cohen nco...@ucsd.edu wrote: Is there a pythonic way to collect and display multiple exceptions at the same time? For example let's say you're trying to validate the elements of a list and you'd like to

Re: idiomatic way to collect and report multiple exceptions?

2010-05-07 Thread Ben Cohen
Apologies for the TABs -- I wrote that example for demonstration purposes in my mail client -- I'll copy and paste from a real code editor in the future. Ben On May 7, 2010, at 3:28 PM, Aahz wrote: In article mailman.2715.1273204222.23598.python-l...@python.org, Ben Cohen nco...@ucsd.edu

idiomatic way to collect and report multiple exceptions?

2010-05-06 Thread Ben Cohen
Is there a pythonic way to collect and display multiple exceptions at the same time? For example let's say you're trying to validate the elements of a list and you'd like to validate as many of the elements as possible in one run and still report exception's raised while validating a failed

Re: idiomatic way to collect and report multiple exceptions?

2010-05-06 Thread Chris Rebert
On Thu, May 6, 2010 at 8:50 PM, Ben Cohen nco...@ucsd.edu wrote: Is there a pythonic way to collect and display multiple exceptions at the same time? For example let's say you're trying to validate the elements of a list and you'd like to validate as many of the elements as possible in one

Re: idiomatic way to collect and report multiple exceptions?

2010-05-06 Thread Terry Reedy
On 5/6/2010 11:50 PM, Ben Cohen wrote: Is there a pythonic way to collect and display multiple exceptions at the same time? For example let's say you're trying to validate the elements of a list and you'd like to validate as many of the elements as possible in one run and still report