输出对象的备份、还原 分类: python 小练习 2014-03-28 11:47 191人阅读 评论(0) 收藏

#coding:utf-8
import sys

f=open('sys_midware.txt','wr')

#保存输出对象

old_stdout=sys.stdout

#重定向输出

sys.stdout=f

sys.stdout.write("should in file f")

#还原输出

sys.stdout=old_stdout
print 'Restore sys.stdout'
print 'should in screen'

版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/think1988/p/4627914.html