title: piping from stdin to a python code in a bash script
body: <p>I have a bash script, f, that contains python code. That python code reads from standard input. I want to be able to call my bash script as follows:</p>
  
  <pre><code>f input.txt &gt; output.txt
  </code></pre>
  
  <p>In the example above, the python code will read from input.txt and will write to output.txt. </p>
  
  <p>I'm not sure how to do this. I know that if I wanted to just write to a file, then my bash script would look like this</p>
  
  <pre><code>#!/bin/bash
  python &lt;&lt; EOPYTHON &gt; output.txt
  #python code goes here
  EOPYTHON
  </code></pre>
  
  <p>I tried changing the second line in the code above to the following, but without luck</p>
  
  <pre><code>python &lt;&lt; EOPYTHON $*
  </code></pre>
  
  <p>I'm not sure how else to go about doing this. Any suggestions?</p>
  
  <p><strong>EDIT</strong>
  I'll give a more concrete example. Consider the following bash script, f</p>
  
  <pre><code>#!/bin/bash
  python &lt;&lt; EOPYTHON 
  import sys
  import fileinput
  for i in fileinput.input():
      sys.stdout.write(i + '\n')
  EOPYTHON
  </code></pre>
  
  <p>I want to run my code with the following command</p>
  
  <pre><code>f input.txt &gt; output.txt
  </code></pre>
  
  <p>How do I change my bash script so that it uses "input.txt" as the input stream?</p>