python所有的print就会自动打印到log.txt

f=open("log.txt","a")
ftmp=sys.stdout
sys.stdout=f
#上面这条语句后,以后所有的print就会自动打印到log.txt中,不再需要print >>f, xxx的形势
print ...
print ...

sys.stdout=ftmp

这条语句后就恢复原样。

https://adeshpande3.github.io/adeshpande3.github.io/Deep-Learning-Research-Review-Week-1-Generative-Adversarial-Nets

https://pages.corifeus.com/github/docker-debian-testing-mongodb-stable

posted @ 2017-11-09 14:49  Viewsky  阅读(471)  评论(0编辑  收藏  举报