title: Making raw_input read from a file
body: <p>I'm trying to test some script which uses <code>raw_input</code>, I have some predefined input files where each line is the appropriate input.
  E.g </p>
  
  <p>input.txt: </p>
  
  <pre><code>y
  n
  y
  ...
  </code></pre>
  
  <p>I'm trying to replace <code>sys.stdin</code> with a file object but something is wrong.</p>
  
  <pre><code>with open("input.txt") as f:
      sys.stdin = f
      con = raw_input("aaa") # in reality this is a function which somewhere calls raw_input
      print con # prints nothing 
      sys.stdin = old # saved earlier
  </code></pre>
  
  <p>I want the function which calls <code>raw_input</code> to get the input from the file rather then the <code>stdin</code>.
  I have several such files and I want to loop over then and report accordingly. E.g in this example I'd like <code>con</code> to contain <code>'y'</code></p>
  
  <p>But obviously:</p>
  
  <pre><code>with open("advanced_test1.in") as f:
      print f.read()
  </code></pre>
  
  <p>prints the file's content as expected.</p>