
f = open('a.txt','w')
print >>sys.stdout,'hello,world'
hello,world
print >>f,'hello,world'
f.close()
输出到屏幕的内容重定向到文件,供参考。
def print(stream):""" print(value, ..., sep=' ', end='\\n', file=sys.stdout)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream) defaults to 缺拍或the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default 伏伍a newline. ""贺雀"
pass
#!/usr/bin/env python#coding=utf-8
from subprocess import Popen, PIPE
import re
def disk_space(pattern="核氏2[0-9]%", message="颤纤CAPACITY WARNING"):
## take shell command output
ps = Popen("df -h", shell=True, stdout=PIPE, stderr=PIPE)
output_lines = ps.stdout.readlines()
for line in output_lines:
line = line.strip()
if re.search(pattern, line):
print "%s %s" %(message, line)
if __name__ == '__main__'茄氏仿:
disk_space()
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)