1

Possible Duplicate:
How do you read from stdin in python

I am new Python convert. I have seen examples of people using this command.

cat file1 file2 | python <script name>

I was wondering how to do that? As in how should my python script handle taking this input.? Sorry I do not know the terms to use to search for this. My guess is it can be used for any unix command?

Thanks.

Community
  • 1
  • 1
Ian McGrath
  • 982
  • 2
  • 10
  • 23

1 Answers1

2

The pipe you see in the shell command is used to route the input of previous command to the next command. So when you cat the files file1 and file2. The output is fed to the python script as input.

So the contents of the two files are available at stdin of your python program, which can be accessed using sys.stdin. Hope that helps.