一、stdin:从标准输入读入数据
script.py
import sys text = sys.stdin.read() words = text.split() for i in words: print i
cat source.txt | script.py | sort
二、argv:获取程序外部向程序传递的参数
script.py
import sys print sys.argv[0] print sys.argv[1]
python script.py arg1 arg2
三、exit():退出当前进程
scrpit.py
import sys def exitfunc(value): print value sys.exit(0) print "hello" try: sys.exit(1) except SystemExit,value: exitfunc(value) print "come?"
python script.py
原文:http://www.cnblogs.com/guosq/p/6515935.html