title: How to avoid StopIteration Error in python
body: <p>I have a line that is pulling in variables from multiple lists and I want it to avoid the <code>StopIteration</code> error that comes up so that it can move onto the next line. At the moment I am using the break function, this avoids the <code>StopIteration</code>, but only gives me the first item in the list and it leaves a blank line after it, if i was to print it out. </p>
  
  <p>Here are two of my iterations that have the same problem.</p>
  
  <pre><code>def compose_line5(self, synset_offset, pointer_list):
      self.line5 = ''''''
      for item in pointer_list:
          self.line5 += '''http://www.example.org/lexicon#'''+synset_offset+''' http://www.monnetproject.eu/lemon#has_ptr '''+pointer_list.next()+'''\n'''            
          break
      return self.line5
  
  def compose_line6(self, pointer_list, synset_list): 
      self.line6 = ''''''
      for item in synset_list:
          self.line6 += '''http://www.example.org/lexicon#'''+pointer_list.next()+''' http://www.monnetproject.eu/lemon#pos '''+synset_list.next()+'''\n'''                      
          break
      return self.line6
  </code></pre>
  
  <p>This is the error I get without the break:</p>
  
  <pre><code>Traceback (most recent call last):
    File "wordnet.py", line 225, in &lt;module&gt;
      wordnet.line_for_loop(my_file)
    File "wordnet.py", line 62, in line_for_loop
      self.compose_line5(self.synset_offset, self.pointer_list)
    File "wordnet.py", line 186, in compose_line5
      self.line5 += '''http://www.example.org/lexicon#'''+self.synset_offset+''' http://www.monnetproject.eu/lemon#has_ptr '''+self.pointer_list.next()+'''\n'''
  StopIteration
  </code></pre>
  
  <p>Is there a quick fix for this or do I have to catch exceptions for every method I use the iter() in?</p>