如何在基于IPython的Jupyter Notebook中捕获所有打印输出?

10

在基于ipython的jupyter笔记本中,我有一个打印一些东西的函数。由于它来自一个库,我不能更改此功能。我们来看看:

def print_something():
    print("something")

以一个例子说明。当我在单元格中运行 print_something() 时,我希望将单元格打印的任何内容保存在文件中。我该怎么做?我尝试了%save%logstart,但由于print没有创建输出,它们不能满足我的需求。


4
https://stackoverflow.com/questions/57112535/saving-the-output-of-a-cell-in-jupyter-notebook-with-a-new-line-after-each-numbe/57113015#57113015 - ComplicatedPhenomenon
谢谢!我的问题的答案已经包含在其他问题中了。我不知道在这种情况下该怎么办,我不认为它是重复的。 - Niclas von Caprivi
这是一个捕获Jupyter单元格输出的cell magic:https://github.com/kolibril13/jupyter-capture-output。导入包,然后键入`%%capture_text --path "cap/foo.txt"。此外,还可以使用%%capture_img%%capture_video`。 - Kolibril
1个回答

27

--no-stderr 是什么意思? - seralouk
--no-stderr 是什么意思? - undefined
1
@seralouk 在答案中提供文档链接;) 选项: --no-stderr 不捕获 stderr。(忽略错误) - Carele

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接