python3 get parameter from command terminal and print input out
<pre><code>lines = []
for line in fileinput.input():
    lines.append(line)
    print(line, end='')
</code></pre>

<p><a href="http://i.stack.imgur.com/3FyUr.png" rel="nofollow"><img src="http://i.stack.imgur.com/3FyUr.png" alt="enter image description here"></a></p>

<p>My question, how can I get 2 into the program and print out content of input.txt at the same time? So far, it would get 2 as a file name and try to open it as a file, not as expected. You see in the pic.</p>

<p>@Eugene already pointed out, in your command:</p>

<pre><code>./whale.py '2' &lt; input.txt
</code></pre>

<blockquote>
  <p><code>input.txt</code> is redirected to the standard input stream. <code>2</code> is going
  into argv.</p>
</blockquote>

<p>The error you got was probably because somehow your script thought <code>argv[1]</code> was the file to open.</p>

<p>try this:</p>

<pre><code>import sys
print "this is sys.argv: {}".format(sys.argv[1])
print "below is STDIN:"
for line in sys.stdin:
    print line
</code></pre>

python linux unix input