6

http://ipython.org/ipython-doc/dev/interactive/tips.html的文档中,它说在命令末尾放置一个分号 (;) 以抑制其输出。这在我的情况下似乎不起作用,因为即使是

>>> \>>> print('Hello');  
--> 'Hello'

我对输出抑制有错误的想法还是这是一个错误?这在 pudb 中工作时尤其烦人,因为在我按“下一步”或“进入”时它会闪烁得可怕。

PS输出既不在我的ubuntu ipython 0.10上,也不在osx lion ipython 0.11上被抑制。虽然在 osx 中闪烁问题更严重,可能是因为 item2.

4

3 回答 3

8

尝试类似的东西1 + 1;。如果没有分号,它应该通过打印它来给你关于结果的反馈(由 格式化repr,尽管它在整数的情况下并不重要) - 我认为它应该是这个输出应该被抑制。shell 不会(也不应该)禁止写入碰巧被引用的文件sys.stdout(这本质上就是print这样做的)。这是完全不同的事情,而不是 shell 的工作。

于 2011-09-21T15:42:01.140 回答
5

添加%%capture为单元格的第一行。例如

%%capture
print('Hello')

这只是丢弃了输出,但%%capture可以使用魔法将输出保存到变量 -请参阅文档

于 2014-05-16T04:57:45.920 回答
1

这是 Dataquest 中的另一个示例— 28 Jupyter Notebook 提示、技巧和快捷方式帖子:

  # Use a semicolon to suppress the output of a final function.
  %matplotlib inline
  from matplotlib import pyplot as plt
  import numpy
  x = numpy.linspace(0, 1, 1000)**1.5
  plt.hist(x); # Output not suppressed w/ semicolon?

还有一个“工作”分号抑制的例子:

x = 1 + 1
x; # Output suppressed w/ semicolon!

因此,它似乎抑制了通常显示在终端中的语句,而不是“内联”类型,如绘图。

于 2018-01-31T15:24:19.850 回答