Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 08:14:18 -0300, Gerard Flanagan <[EMAIL PROTECTED]> escribió: > Mea culpa. Ego te absolvo in nomine Patris Guidii et Filii Python et Spiritus Sancti Computatorium. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list

Re: catching exceptions from an except: block

2007-03-09 Thread Gerard Flanagan
On Mar 9, 11:57 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 09 Mar 2007 07:30:20 -0300, Gerard Flanagan > <[EMAIL PROTECTED]> escribió: > > >> There is a serious flaw on this approach, the function can't return any > >> false value (it would be treated as a failure). > > > I was te

Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 07:30:20 -0300, Gerard Flanagan <[EMAIL PROTECTED]> escribió: >> There is a serious flaw on this approach, the function can't return any >> false value (it would be treated as a failure). > > I was teaching myself decorators more than anything, so it's not > thought out to an

Re: catching exceptions from an except: block

2007-03-09 Thread Gerard Flanagan
On Mar 9, 9:56 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 09 Mar 2007 04:49:59 -0300, Gerard Flanagan > <[EMAIL PROTECTED]> escribió: > > > Another version: > > > import exceptions > > As back in time as I could go (Python 1.5), exceptions were available as > builtins... > I did

Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 05:52:35 -0300, Duncan Booth <[EMAIL PROTECTED]> escribió: > "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > >> Not the *previous* exception, but the *current* one. You must be >> inside an "except" clause to use a bare raise. >> > No, you don't have to be inside an except

Re: catching exceptions from an except: block

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 04:49:59 -0300, Gerard Flanagan <[EMAIL PROTECTED]> escribió: > Another version: > > import exceptions As back in time as I could go (Python 1.5), exceptions were available as builtins... > def onfailFalse(fn): > def inner(*args, **kwargs): > try: >

Re: catching exceptions from an except: block

2007-03-09 Thread Duncan Booth
"Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > Not the *previous* exception, but the *current* one. You must be > inside an "except" clause to use a bare raise. > No, you don't have to be inside an except clause to use a bare raise. A bare 'raise' will re-raise the last exception that was act

Re: catching exceptions from an except: block

2007-03-08 Thread Gerard Flanagan
On Mar 8, 10:31 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 08 Mar 2007 06:17:37 -0300, Gerard Flanagan > <[EMAIL PROTECTED]> escribió: > > > @onfail(False) > > def a(x): > > if x == 1: > > return 'function a succeeded' > > else: > > raise > > I know it's ir

Re: catching exceptions from an except: block

2007-03-08 Thread Gabriel Genellina
En Thu, 08 Mar 2007 21:11:54 -0300, Steven D'Aprano <[EMAIL PROTECTED]> escribió: >>> @onfail(False) >>> def a(x): >>> if x == 1: >>> return 'function a succeeded' >>> else: >>> raise > > I thought "raise" on its own was supposed to re-raise the previous > exception, but

Re: catching exceptions from an except: block

2007-03-08 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > Are you saying it only works as advertised within the except clause of a > try...except block? I think that's the idea. It hadn't occurred to me that it could be used any other way, but I don't have the docs in front of me right now, so maybe I missed

Re: catching exceptions from an except: block

2007-03-08 Thread Steven D'Aprano
On Thu, 08 Mar 2007 16:19:27 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> I thought "raise" on its own was supposed to re-raise the previous >> exception, but I've just tried it in the interactive interpreter and it >> doesn't work for me. > > It means you can catch a

Re: catching exceptions from an except: block

2007-03-08 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > I thought "raise" on its own was supposed to re-raise the previous > exception, but I've just tried it in the interactive interpreter and it > doesn't work for me. It means you can catch an exception, do stuff with it, and then pass it upward to earlie

Re: catching exceptions from an except: block

2007-03-08 Thread Steven D'Aprano
On Thu, 08 Mar 2007 06:31:20 -0300, Gabriel Genellina wrote: > En Thu, 08 Mar 2007 06:17:37 -0300, Gerard Flanagan > <[EMAIL PROTECTED]> escribió: > >> @onfail(False) >> def a(x): >> if x == 1: >> return 'function a succeeded' >> else: >> raise > > I know it's irrelevan

Re: catching exceptions from an except: block

2007-03-08 Thread Gabriel Genellina
En Thu, 08 Mar 2007 06:17:37 -0300, Gerard Flanagan <[EMAIL PROTECTED]> escribió: > @onfail(False) > def a(x): > if x == 1: > return 'function a succeeded' > else: > raise I know it's irrelevant, as you use a bare except, but such raise looks a bit ugly... -- Gabriel

Re: catching exceptions from an except: block

2007-03-08 Thread Gerard Flanagan
On Mar 7, 7:32 pm, "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote: > Hi all, > > Imagine I have three functions a(x), b(x), c(x) that each return > something or raise an exception. Imagine I want to define a function > that returns a(x) if possible, otherwise b(x), otherwise c(x), > otherwise raise

Re: catching exceptions from an except: block

2007-03-08 Thread Bruno Desthuilliers
MonkeeSage a écrit : > On Mar 7, 4:58 pm, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: >>except_retry: # the missing(???) keyword you're after > > What is 'except_retry'? A totally imaginary statement that would do what the OP is looking for. > To the OP, with the loop and the callables

Re: catching exceptions from an except: block

2007-03-07 Thread Steven D'Aprano
On Wed, 07 Mar 2007 10:32:53 -0800, Arnaud Delobelle wrote: > Hi all, > > Imagine I have three functions a(x), b(x), c(x) that each return > something or raise an exception. Imagine I want to define a function > that returns a(x) if possible, otherwise b(x), otherwise c(x), > otherwise raise Can

Re: catching exceptions from an except: block

2007-03-07 Thread MonkeeSage
On Mar 7, 4:58 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >except_retry: # the missing(???) keyword you're after What is 'except_retry'? To the OP, with the loop and the callables you could also break out of the loop when the condition is met and use the else condition to raise the ex

Re: catching exceptions from an except: block

2007-03-07 Thread Diez B. Roggisch
Arnaud Delobelle schrieb: > On Mar 7, 8:52 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > [snip] >> Without knowing more about the functions and the variable it is somewhat >> hard to tell what you are trying to accomplish. If a, b, c are functions >> that act on x when it is a different type, chang

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Gabriel Genellina a écrit : > En Wed, 07 Mar 2007 18:48:18 -0300, Arnaud Delobelle > <[EMAIL PROTECTED]> escribió: > >> for f in int, float, complex: >> try: >> return f(x) >> except ValueError: >> continue >> raise CantDoIt >> >> But if the three things I want to do are

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Arnaud Delobelle a écrit : > On Mar 7, 8:52 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > [snip] > >>Without knowing more about the functions and the variable it is somewhat >>hard to tell what you are trying to accomplish. If a, b, c are functions >>that act on x when it is a different type, chan

Re: catching exceptions from an except: block

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 18:48:18 -0300, Arnaud Delobelle <[EMAIL PROTECTED]> escribió: > for f in int, float, complex: > try: > return f(x) > except ValueError: > continue > raise CantDoIt > > But if the three things I want to do are not callable objects but > chunks of code

Re: catching exceptions from an except: block

2007-03-07 Thread garrickp
On Mar 7, 3:04 pm, [EMAIL PROTECTED] wrote: > On Mar 7, 2:48 pm, "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote: > > > > > > > I'm not really thinking about this situation so let me clarify. Here > > is a simple concrete example, taking the following for the functions > > a,b,c I mention in my origin

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Gabriel Genellina a écrit : > En Wed, 07 Mar 2007 19:00:59 -0300, Bruno Desthuilliers > <[EMAIL PROTECTED]> escribió: > >> this kind of cose is exactly what OO polymorphic dispatch is supposed to > > > this kind of cose? sorry s/cose/code/ > Ce genre de chose? > En quelques sortes, oui, quo

Re: catching exceptions from an except: block

2007-03-07 Thread garrickp
On Mar 7, 2:48 pm, "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote: > > I'm not really thinking about this situation so let me clarify. Here > is a simple concrete example, taking the following for the functions > a,b,c I mention in my original post. > - a=int > - b=float > - c=complex > - x i

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Arnaud Delobelle a écrit : > Hi all, > > Imagine I have three functions a(x), b(x), c(x) that each return > something or raise an exception. Imagine I want to define a function > that returns a(x) if possible, otherwise b(x), otherwise c(x), > otherwise raise CantDoIt. > > Here are three ways I

Re: catching exceptions from an except: block

2007-03-07 Thread Arnaud Delobelle
On Mar 7, 8:52 pm, Larry Bates <[EMAIL PROTECTED]> wrote: [snip] > Without knowing more about the functions and the variable it is somewhat > hard to tell what you are trying to accomplish. If a, b, c are functions > that act on x when it is a different type, change to one function that > can hand

Re: catching exceptions from an except: block

2007-03-07 Thread Gabriel Genellina
En Wed, 07 Mar 2007 19:00:59 -0300, Bruno Desthuilliers <[EMAIL PROTECTED]> escribió: > this kind of cose is exactly what OO polymorphic dispatch is supposed to this kind of cose? Ce genre de chose? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Larry Bates a écrit : (snip) > def d(x): > if isinstance(x, basestring): > # > # Code here for string > # > elif isinstance(x, int): > # > # Code here for int > # > elif isinstance(x, float): > # > # Code here for string >

Re: catching exceptions from an except: block

2007-03-07 Thread Bruno Desthuilliers
Miki a écrit : > Hello Arnaud, > > >>Imagine I have three functions a(x), b(x), c(x) that each return >>something or raise an exception. Imagine I want to define a function >>that returns a(x) if possible, otherwise b(x), otherwise c(x), >>otherwise raise CantDoIt. > > Exceptions are for error

Re: catching exceptions from an except: block

2007-03-07 Thread Larry Bates
Arnaud Delobelle wrote: > Hi all, > > Imagine I have three functions a(x), b(x), c(x) that each return > something or raise an exception. Imagine I want to define a function > that returns a(x) if possible, otherwise b(x), otherwise c(x), > otherwise raise CantDoIt. > > Here are three ways I can

Re: catching exceptions from an except: block

2007-03-07 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Miki wrote: > Exceptions are for error handling, not flow control. That's not true, they are *exceptions* not *errors*. They are meant to signal exceptional situations. And at least under the cover it's used in every ``for``-loop because the end condition is signaled by

Re: catching exceptions from an except: block

2007-03-07 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Arnaud Delobelle wrote: > # This one only works because a,b,c are functions > # Moreover it seems like an abuse of a loop construct to me > def rolled_first(x): > for f in a, b, c: > try: > return f(x) > except: > continue > r

Re: catching exceptions from an except: block

2007-03-07 Thread Arnaud Delobelle
On 7 Mar, 19:26, "Miki" <[EMAIL PROTECTED]> wrote: > Hello Arnaud, Hi Miki [snip] > Exceptions are for error handling, not flow control. Maybe but it's not always that clear cut! As error handling is a form of flow control the two have to meet somewhere. [snip] > As a side note, try to avoid "c

Re: catching exceptions from an except: block

2007-03-07 Thread Miki
Hello Arnaud, > Imagine I have three functions a(x), b(x), c(x) that each return > something or raise an exception. Imagine I want to define a function > that returns a(x) if possible, otherwise b(x), otherwise c(x), > otherwise raise CantDoIt. Exceptions are for error handling, not flow control.

catching exceptions from an except: block

2007-03-07 Thread Arnaud Delobelle
Hi all, Imagine I have three functions a(x), b(x), c(x) that each return something or raise an exception. Imagine I want to define a function that returns a(x) if possible, otherwise b(x), otherwise c(x), otherwise raise CantDoIt. Here are three ways I can think of doing it: -- # This o