Stephen Thorne wrote:
> We've all seen it before. Its a horrible idiom that you would achieve
> in another language by doing:
>
> if (m = foo_pattern.search(subject))
> { }
> else
> { }
>
> but it occured to me today, that it is possible to do it in python
> without the extra line.
>
> '>>> for m in xsearch(foo_pattern, subject):
> '>>>     pass
> '>>> else:
> '>>>     pass
>
> simple, concise, requires no new syntax, and is only a little
confusing[1]!

It won't have quite the same effect though, as the 'else' statement is
*always* called after the 'for' loop completes.

To have the functionality you're after, you need to include a break in
the code block within the loop.

- alex23

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to