- 论坛徽章:
- 0
|
最近在看python cookbook,对于下面一段- #!/usr/bin/python
- import os,sys
- nargs = len(sys.argv)
- if not 3 <= nargs <= 5:
- print "usage:%s search_text replace_text [infile [outfile]]" % os.path.basename(sys.argv[0])
- else:
- stext = sys.argv[1]
- rtext = sys.argv[2]
- input_file = sys.stdin
- output_file = sys.stdout
- if nargs > 3:
- input_file = open(sys.argv[3])
- if nargs > 4:
- output_file = open(sys.argv[4],'w')
- for a in input_file:
- output_file.write(a.replace(stext,rtext))
- output_file.close()
- input_file.close()
复制代码 中的input_file = sys.stdin,output_file = sys.stdout这两句,不知道作用是什么,麻烦大家帮忙解释一下,先谢谢了 |
|