sys.stdin:
A standard source of data input is sys.stdin. When a program reads from standard input, you can supply text by typing it, or you can link it with the standard output of another program, using a pipe(This is a standard UNIX concept.)
sys.stdout:
The text you give to print appears in sys.stdout. The prompts for input and raw_input also go there. Data written to sys.stdout typically appears on your screen, but can be rerouted to the standard input of another program with a pipe, as mentioned.
sys.stderr:
Error messages (such as stack traces) are written to sys.stderr. In many ways, it is similar to sys.stdout
Simple Script That Counts the Words in sys.stdin:
# somescript.py
import sys
text = sys.stdin.read()
words = text.split()
wordcount = len(words)
print 'Wordcount:', wordcount
file somefile.txt contain text like: 1 2 3 4 5 6
Here are the results of linux command: $cat somefile.txt | python somescript.py:
Wordcount: 6