Re: breaking out of outer loops

2016-03-07 Thread Mark Lawrence
On 07/03/2016 23:09, Fillmore wrote: I must be missing something simple because I can't find a way to break out of a nested loop in Python. Is there a way to label loops? For the record, here's a Perl script of mine I'm trying to port...there may be 'malformed' lines in a TSV file I'm parsing

Re: breaking out of outer loops

2016-03-07 Thread Terry Reedy
On 3/7/2016 6:49 PM, Chris Angelico wrote: On Tue, Mar 8, 2016 at 10:42 AM, Chris Kaynor wrote: And the same rough example, using an exception without a function: for file in files: try: for line in file: section = line.split() for section in line:

Re: breaking out of outer loops

2016-03-07 Thread Mark Lawrence
On 07/03/2016 23:09, Fillmore wrote: I must be missing something simple because I can't find a way to break out of a nested loop in Python. Is there a way to label loops? For the record, here's a Perl script of mine I'm trying to port...there may be 'malformed' lines in a TSV file I'm parsing

Re: breaking out of outer loops

2016-03-07 Thread Joel Goldstick
On Mon, Mar 7, 2016 at 7:13 PM, Fillmore wrote: > On 3/7/2016 7:08 PM, Chris Angelico wrote: > > >> Yep, which is why we're offering a variety of new paradigms. Because >> it's ever so much easier to get your head around three than one! >> >> We are SO helpful, guys. So helpful. :) >> > > not too

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 7:08 PM, Chris Angelico wrote: Yep, which is why we're offering a variety of new paradigms. Because it's ever so much easier to get your head around three than one! We are SO helpful, guys. So helpful. :) not too dissimilarly from human languages, speaking a foreign language is

Re: breaking out of outer loops

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 11:02 AM, Fillmore wrote: > On 3/7/2016 6:09 PM, Fillmore wrote: >> >> >> I must be missing something simple because I can't find a way to break >> out of a nested loop in Python. > > > Thanks to everyone who has tried to help so far. I suspect this may be a > case where I j

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 6:09 PM, Fillmore wrote: I must be missing something simple because I can't find a way to break out of a nested loop in Python. Thanks to everyone who has tried to help so far. I suspect this may be a case where I just need to get my head around a new paradigm -- https://mail.

Re: breaking out of outer loops

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 10:42 AM, Chris Kaynor wrote: > And the same rough example, using an exception without a function: > > for file in files: > try: > for line in file: > section = line.split() > for section in line: > if sectionCorrupt: >

Re: breaking out of outer loops

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 10:09 AM, Fillmore wrote: > For the record, here's a Perl script of mine I'm trying to port...there may > be 'malformed' lines in a TSV file I'm parsing that are better discarded > than fixed. > > my $ctr = 0; > OUTER: > while($line = ) { > > $ctr++; > if ($ctr < 5)

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 6:29 PM, Rob Gaddi wrote: You're used to Perl, you're used to exceptions being A Thing. This is Python, and exceptions are just another means of flow control. class MalformedLineError(Exception): pass for line in file: try: for part in line.split('\t'):

Re: breaking out of outer loops

2016-03-07 Thread Chris Kaynor
On Mon, Mar 7, 2016 at 3:21 PM, Fillmore wrote: > On 3/7/2016 6:17 PM, Ian Kelly wrote: > >> On Mon, Mar 7, 2016 at 4:09 PM, Fillmore >> wrote: >> >>> >>> I must be missing something simple because I can't find a way to break >>> out >>> of a nested loop in Python. >>> >>> Is there a way to labe

Re: breaking out of outer loops

2016-03-07 Thread Rob Gaddi
Fillmore wrote: > > I must be missing something simple because I can't find a way to break > out of a nested loop in Python. > > Is there a way to label loops? > > For the record, here's a Perl script of mine I'm trying to port...there > may be 'malformed' lines in a TSV file I'm parsing that ar

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 6:17 PM, Ian Kelly wrote: On Mon, Mar 7, 2016 at 4:09 PM, Fillmore wrote: I must be missing something simple because I can't find a way to break out of a nested loop in Python. Is there a way to label loops? No, you can't break out of nested loops, wow...this is a bit of a WTF

Re: breaking out of outer loops

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 4:09 PM, Fillmore wrote: > > I must be missing something simple because I can't find a way to break out > of a nested loop in Python. > > Is there a way to label loops? No, you can't break out of nested loops, apart from structuring your code such that return does what you

breaking out of outer loops

2016-03-07 Thread Fillmore
I must be missing something simple because I can't find a way to break out of a nested loop in Python. Is there a way to label loops? For the record, here's a Perl script of mine I'm trying to port...there may be 'malformed' lines in a TSV file I'm parsing that are better discarded than fix

Re: breaking out of outer loops

2008-02-06 Thread Antoon Pardon
On 2008-01-29, Jeremy Sanders <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> Any elegant way of breaking out of the outer for loop than below, I >> seem to have come across something, but it escapes me >> >> for i in outerLoop: >>for j in innerLoop: >>if condition: >>

Re: breaking out of outer loops

2008-01-29 Thread Steven Bethard
Jeremy Sanders wrote: > [EMAIL PROTECTED] wrote: > >> Any elegant way of breaking out of the outer for loop than below, I >> seem to have come across something, but it escapes me >> >> for i in outerLoop: >>for j in innerLoop: >>if condition: >> break >>else: >>co

Re: breaking out of outer loops

2008-01-29 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > Any elegant way of breaking out of the outer for loop than below, I > seem to have come across something, but it escapes me > > for i in outerLoop: >for j in innerLoop: >if condition: > break >else: >continue > break It's working

Re: breaking out of outer loops

2008-01-29 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote: > Any elegant way of breaking out of the outer for loop than below, I > seem to have come across something, but it escapes me > > for i in outerLoop: >for j in innerLoop: >if condition: > break >else: >continue > break Perhaps Python

Re: breaking out of outer loops

2008-01-29 Thread Arnaud Delobelle
On Jan 29, 8:55 pm, pataphor <[EMAIL PROTECTED]> wrote: > On Tue, 29 Jan 2008 11:51:04 -0800 (PST) > > [EMAIL PROTECTED] wrote: > > Any elegant way of breaking out of the outer for loop than below, I > > seem to have come across something, but it escapes me > > > for i in outerLoop: > >    for j in

Re: breaking out of outer loops

2008-01-29 Thread pataphor
On Tue, 29 Jan 2008 11:51:04 -0800 (PST) [EMAIL PROTECTED] wrote: > Any elegant way of breaking out of the outer for loop than below, I > seem to have come across something, but it escapes me > > for i in outerLoop: >for j in innerLoop: >if condition: > break >else: >

Re: breaking out of outer loops

2008-01-29 Thread Paul Rubin
[EMAIL PROTECTED] writes: > Any elegant way of breaking out of the outer for loop than below, I > seem to have come across something, but it escapes me > > for i in outerLoop: >for j in innerLoop: >if condition: > break >else: >continue > break You can do it

breaking out of outer loops

2008-01-29 Thread noemailplease0001
Any elegant way of breaking out of the outer for loop than below, I seem to have come across something, but it escapes me for i in outerLoop: for j in innerLoop: if condition: break else: continue break Thanks, K -- http://mail.python.org/mailman/listinfo/python