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
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
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
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
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
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:
>
"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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
>
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
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
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
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
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
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.
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
36 matches
Mail list logo