【发布时间】:2017-06-02 22:22:41
【问题描述】:
在将 Jupyter 笔记本的输出发送到文件后,如何将其输出设置回输出单元格?
将其输出发送到文件:
sys.stdout = open(filename, 'w')
print "stuff"
将其输出发送回输出单元:
sys.stdout = ?
print "hopefully this is in an output cell now"
【问题讨论】:
-
Redirect stdout to a file in Python? 的可能重复第二个答案比公认的要好得多,因为它确保正确清理并避免编写一堆手动代码。