[Python-Dev] Chaining try statements: eltry?

Thomas Lotze thomas at thomas-lotze.de
Fri Jul 8 11:21:47 CEST 2005


Ron Adam <rrr at ronadam.com> wrote:

> 1. With an if, if you think in terms of flow testing you get the same 
> results as if you look at it in in terms of value testing.  Either the
> if-block will execute or the else-block will, but never any part of
> one  and then the other.  A binary solution to a binary problem.
> 
> 2. With a try, It's a value test for no exception. Or you could
> consider  it flow test for the try block completing.

You might also look at it like this: There's a correspondence between
the if and try statements with if/elif corresponding to except and else
having the same meaning in both cases. With the exception of the try
suite that sets the stage for exception handlers, both statements give
you a set of branches (if/elif/else suites and execpt/else suites,
resp.) exactly one of which will execute.

Which is one of the reasons why I came to think of my proposal starting
this thread of being half-baked at best...

> 3. In a while loop, it's a value test, where the else block gets 
> executed if the while condition evaluates as false, the while block
> may  or may not execute. You still need a flag to test for that.

You're effectively arguing for do...while, right?

> 4. In a for loop, it's a test of the iterator completing and
> generating  a StopIteration exception.  Which is somewhat implicit. 
> The for block  may or may not execute.

This is something different IMO. You don't want to model condition
testing, you want to act on a set of values which may or may not be
empty. That's why I think you actually want the StopIteration stuff to
be implicit.

-- 

Viele Grüße,
Thomas


More information about the Python-Dev mailing list