标签:pytho sys root style python his logs out span
输出有两种,一种是标准输出,一种是标准错误输出,python 处理标准输出使用 sys.stdout ,处理标准错误输出用 sys.stderr
In [2]: import sys In [3]: sys.stdout.write(‘Hello World‘) # 标准输出(看起来跟print用法一致) Hello World In [4]: sys.stderr.write(‘Hello World‘) # 标准错误输出 Hello World
[root@localhost ~]# cat 1.py #!/usr/bin/python import sys sys.stdout.write(‘This is a stdout\n‘) sys.stderr.write(‘This is a stderr\n‘) [root@localhost ~]# python 1.py > /dev/null # 结果只显示标准错误输出 This is a stderr [root@localhost ~]# python 1.py 2> /dev/null # 结果只显示标准输出 This is a stdout
标签:pytho sys root style python his logs out span
原文地址:http://www.cnblogs.com/pzk7788/p/7425264.html