如何将输出发送到文件后将Jupyter笔记本的输出设置回输出单元格?
将其输出发送到文件:
sys.stdout = open(filename, 'w')
print "stuff"
将其输出发送回输出单元格:
sys.stdout = ?
print "hopefully this is in an output cell now"
答案 0 :(得分:3)
使用临时变量:
stdout_backup = sys.stdout
将其输出发送到文件:
sys.stdout = open(filename, 'w')
print "stuff"
将其输出发送回输出单元格:
sys.stdout = stdout_backup
print "this is in an output cell now"