sys.stdout sys.stderr的用法

stdout:标准输出

stderr:标准错误

print  相当于 sys.stdout.write() + 换行

 

一个将数据流写入文件的程序,文件名为:main.py

def main(out=sys.stdout):
    config = 'Hello'
    out.write(config)

if __name__ == '__main__':
    main()

在命令行下运行

main.py > abcdfg.txt

就会将Hello字符串写进abcdfg.txt文件中

具体看这里:

http://hi.baidu.com/liuhelishuang/item/41f2bbf21b676215ce9f32bb

posted @ 2013-08-16 10:54  践道者  阅读(2484)  评论(0编辑  收藏  举报