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>The content of the <code>input.txt</code> file can be accesed using the <code>sys.stdin</code> file handle from inside python.
The arguments must be accesed using the <code>sys.argv</code> array.</p>

<p>Here is a sample script.</p>

<pre><code>#!/usr/bin/python
import sys
arg=sys.argv[1] #take first argument
lines=[]
for line in sys.stdin:
  lines.append(line) # save line from stdin to the array. Watch out for memory usage.


print arg
print lines
</code></pre>

python linux unix input