breaking out of outer loops

Fillmore fillmore_remove at hotmail.com
Mon Mar 7 18:40:03 EST 2016


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'):
>              if thispartisbadforsomereason:
>                  raise MalformedLineError()
>              otherwisewedothestuff
>      except MalformedLineError:
>          pass
>

I am sure you are right, but adapting this thing here into something 
that is a fix to my problem seems like abusing my 'system 2' (for those 
who read a certain book by a guy called Daniel Kanheman :)




More information about the Python-list mailing list