【发布时间】:2013-06-16 19:13:34
【问题描述】:
寻找一些帮助记录/保存打印到如下所示的两个文件位置,有人知道这样做的方法吗?
### Create output file/open it for editing
output_file = open('FILE.txt','w')
output_file1 = open('FILE_APPENDING.txt','a')
## Create a backup of current setting
old_stdout = sys.stdout
sys.stdout = output_file
sys.stdout = output_file1
print "stuff here"
## loop here printing stuff
## Revert python to show prints as normal
sys.stdout=old_stdout
## Close the file we are writing too
output_file.close()
output_file1.close()
提前致谢 - 海福克斯
【问题讨论】:
-
为什么不直接使用
file.write?
标签: python logging python-2.7 stdout output