title: Read input from redirected stdin with python
body: <p>I have this loop that reads lines from stdin until a newline is entered, however, this only works from typing in the input. How do I get the program to read lines from a redirected stdin via the command line?</p>
  
  <p>For instance:</p>
  
  <pre><code>$ python graph.py &lt; input.input
  </code></pre>
  
  <p>Here is the loop I have to read lines from input:</p>
  
  <pre><code>while 1:
       line = sys.stdin.readline()
       if line == '\n':
           break
       try:
         lines.append(line.strip())
       except:
         pass
  </code></pre>