如何将Jupyter笔记本输出设置回输出单元?

时间:2017-01-18 13:47:12

标签: python jupyter-notebook

如何将输出发送到文件后将Jupyter笔记本的输出设置回输出单元格?

将其输出发送到文件:

sys.stdout = open(filename, 'w')
print "stuff"

将其输出发送回输出单元格:

sys.stdout = ?
print "hopefully this is in an output cell now"

1 个答案:

答案 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"