On Mon, May 13, 2019 at 3:26 AM David Mertz <me...@gnosis.cx> wrote:
>
> To be clear in this thread, I don't think I'm really ADVOCATING for a 
> multi-level break.  My comments are simply noting that I personally fairly 
> often encounter the situation where they would be useful.  At the same time, 
> I worry about Python gaining sometimes-useful features that complicate the 
> overall language and bring it closer to Perl's "everyone can write in their 
> own style."
>
> So to answer Chris' question... well, i did find something recent, but it has 
> a ton of other extraneous stuff.  But I've simplified to something that isn't 
> that much different from my example from my tablet yesterday, but is fairly 
> realistic still.
>
> I have an existing function that looks roughly like this:
>
> def find_needle_in_haystacks():
>     found_needle = False
>     for haystack in glob.glob('path/to/stuff/*'):
>         fh = open(fname)
>         header = fh.readline()
>         if get_format(header) == 'foo':
>             for line in fh:
>                 status = process_foo(line)
>                 if status = -1:
>                     found_needle = True
>                     break
>         elif get_format(header) == 'bar':
>             for line in fh:
>                 status = process_bar(line)
>                 if status = -1:
>                     found_needle = True
>                     break
>
>         if found_needle:
>             break
>

Cool. How much code is there AFTER this loop? The most obvious way to
handle this is to immediately 'return' instead of multi-level
breaking.

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to