title: Iterate over the lines of a string
body: <p>I have a multi-line string defined like this:</p>
  
  <pre><code>foo = """
  this is 
  a multi-line string.
  """
  </code></pre>
  
  <p>This string we used as test-input for a parser I am writing. The parser-function receives a <code>file</code>-object as input and iterates over it. It does also call the <code>next()</code> method directly to skip lines, so I really need an iterator as input, not an iterable.
  I need an iterator that iterates over the individual lines of that string like a <code>file</code>-object would over the lines of a text-file. I could of course do it like this:</p>
  
  <pre><code>lineiterator = iter(foo.splitlines())
  </code></pre>
  
  <p>Is there a more direct way of doing this? In this scenario the string has to traversed once for the splitting, and then again by the parser. It doesn't matter in my test-case, since the string is very short there, I am just asking out of curiosity. Python has so many useful and efficient built-ins for such stuff, but I could find nothing that suits this need.</p>