[Guido, prsenting a use case]
> > block locking(myLock, timeout=30):
> > ...code executed with lock held...
> > else:
> > ...code executed if lock not acquired...
[Anders Munch]
> A file-closing block function has the same need, as does any block
> function that manages a resource,
On Mon, 02 May 2005 07:46:31 -0600, Shane Hathaway <[EMAIL PROTECTED]> wrote:
>Anders J. Munch wrote:
>> in opening('file1') as f1:
>> ...
>> in opening('file2') as f2:
>> ...
>> except IOError:
>> print "file1 not available, I'll try again later"
>>
>> I
Anders> How do I tell try/except that I really only meant to trap
Anders> opening('file1'), but opening 'file2' is not supposed to fail so
Anders> I want any exception from that propagated? Better if I could
Anders> write:
Anders> in opening('file1') as f1:
Anders>
Anders J. Munch wrote:
> in opening('file1') as f1:
> ...
> in opening('file2') as f2:
> ...
> except IOError:
> print "file1 not available, I'll try again later"
>
> I rather like this version, because it is patently clear what should
> happen if there
GvR wrote:
> [Nick Coghlan]
> > Option 2: mimic if semantics
> >An 'else' clause on a block statement behaves vaguely like the else
clause on
> > an if statement - the clause is executed only if the first suite is
never
> > entered, but no exception occurs (i.e. StopIteration is raised by the
f
Nick Coghlan wrote:
> Option 1: mimic try, for, while semantics
>An 'else' clause on a block statement behaves like the else clause on
> for and while loops, and on try/except statements - the clause is
> executed only if the managed suite completes 'normally' (i.e. it is not
> terminated e
[Nick Coghlan]
> As yet, I don't have a particularly firm opinion on whether or not block
> statements should support an 'else:' clause. And there are obviously a great
> many other questions to be answered about how block statements might work that
> are more important than this one.
>
> Still, I
On Sun, May 01, 2005, Nick Coghlan wrote:
>
> Option 0:
>No else clause allowed. Figured I should mention this, since it is
>Guido's last reported inclination, and my total lack of use cases for the
> other options below suggests this is the best idea for an initial
> implementation.
+1
As yet, I don't have a particularly firm opinion on whether or not block
statements should support an 'else:' clause. And there are obviously a great
many other questions to be answered about how block statements might work that
are more important than this one.
Still, I've been tinkering with