"also" to balance "else" ?

Nicolas Fleury nid_oizo at yahoo.com_remove_the_
Wed Jun 15 18:06:22 EDT 2005


Ron Adam wrote:
> It occurred to me (a few weeks ago while trying to find the best way to 
> form a if-elif-else block, that on a very general level, an 'also' 
> statement might be useful.  So I was wondering what others would think 
> of it.

But the feature is already there:

for x in <iterable>:
     BLOCK1
     if <condition>:
         ALSO-BLOCK
         break
else:
     BLOCK2

If find "else" fine, since the only times I used it is in searches:

for x in <iterable>
     BLOCK1
     if <gotcha-condition>: break
else:
     raise Exception('Not found')

In that case, 'else' sounds like the good keyword.

Regards,
Nicolas



More information about the Python-list mailing list