你如何在运行 IPython 的 Jupyter 中抑制输出? [英] How do you suppress output in Jupyter running IPython?
本文介绍了你如何在运行 IPython 的 Jupyter 中抑制输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何抑制输出到stdout
?
分号可用于抑制返回对象的显示,例如
<预><代码>>>>1+12>>>1+1;# 没有输出!但是,打印到标准输出的函数不受分号的影响.
<预><代码>>>>打印('你好!')你好!>>>我的功能()计算值...如何抑制print
/MyFunction
的输出?
解决方案
添加 %%capture
作为单元格的第一行.例如
%%capture打印('你好')我的功能()
这只是丢弃输出,但 %%capture
魔法可用于将输出保存到变量 - 查阅文档
How can output to stdout
be suppressed?
A semi-colon can be used to supress display of returned objects, for example
>>> 1+1
2
>>> 1+1; # No output!
However, a function that prints to stdout is not affected by the semi-colon.
>>> print('Hello!')
Hello!
>>> MyFunction()
Calculating values...
How can the output from print
/ MyFunction
be suppressed?
解决方案
Add %%capture
as the first line of the cell. eg
%%capture
print('Hello')
MyFunction()
This simply discards the output, but the %%capture
magic can be used to save the output to a variable - consult the docs
这篇关于你如何在运行 IPython 的 Jupyter 中抑制输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文