title: Python: Rerun try-except loop
body: <p>I'm trying to rerun a try-except loop each time there is an error and only break when there is no error.</p>
  
  <pre><code>loop = True;
      while loop == True:
          try:
              for i in data_names:
                  #do something
          except Exception, e:
              e = str(e)[0:100];
              parse_error_list.append(str(e)[str(e).rindex(':')+2:str(e).rindex(':')+4]);
  
              if len(e) == 0:
                  loop = False;
  </code></pre>
  
  <p>As a sanity check, will the following allow me to exit the loop if and only if there is no error? </p>
  
  <p>EDIT: Is the answer? If so, is this the most efficient implementation? ...</p>
  
  <pre><code>loop = True;
      while loop:
          try:
              for i in data_names:
                  #do something
          except Exception, e:
              e = str(e)[0:100];
              parse_error_list.append(str(e)[str(e).rindex(':')+2:str(e).rindex(':')+4]);
  
          if e:
              loop = False;
  </code></pre>