title: Read Python stdin from pipe, without blocking on empty input
body: <p>I am trying to read stdin in a Python script, while receiving from pipe.</p>
  
  <p>I used these lines:</p>
  
  <pre><code>for line in sys.stdin:
      print line
  </code></pre>
  
  <p>And run the script: <code>echo "test" | script.py</code></p>
  
  <p>So far it works fine. However if I don't use a pipe the program sticks at the <code>for</code> command. Meaning that calling: <code>./script.py</code> will make the script not work. How can I fix this?</p>