title: Python: Nice way to iterate over shell command result
body: <p>is there a "nice" way to iterate over the output of a shell command?</p>
  
  <p>I'm looking for the python equivalent for something like:</p>
  
  <pre><code>ls | while read file; do
      echo $file
  done
  </code></pre>
  
  <p>Note that 'ls' is only an example for a shell command which will return it's result in multiple lines and of cause 'echo' is just: do something with it.</p>
  
  <p>I known of these alternatives: <a href="https://stackoverflow.com/questions/89228/calling-an-external-command-in-python">Calling an external command in Python</a> but I don't know which one to use or if there is a "nicer" solution to this. (In fact "nicer" is the main focus of this question.)</p>
  
  <p>This is for replacing some bash scripts with python.</p>