在http://ipython.org/ipython-doc/dev/interactive/tips.html的文档中,它表示在命令末尾加上分号(;)来抑制其输出。在我的情况下,这似乎不适用于
>>> \>>> print('Hello');
--> 'Hello'
我对输出抑制有错误的想法,还是这个错误?在pudb工作时这尤其令人讨厌,因为当我按下“next”或“step into”时,它在我的情况下会出现可怕的闪烁。
P.S输出既不是我的ubuntu ipython 0.10也不是osx lion ipython 0.11。虽然osx中的闪烁问题更糟糕,可能是因为item2。
答案 0 :(得分:5)
尝试1 + 1;
之类的内容。如果没有分号,它应该通过打印给你关于结果的反馈(由repr
格式化,虽然在整数的情况下无关紧要) - 我认为这个输出应该被抑制。 shell不会(也不应该)禁止写入恰好由sys.stdout
引用的文件(这基本上是print
所做的)。这是一个完全不同的问题,而不是shell的工作。
答案 1 :(得分:4)
添加%%capture
作为单元格的第一行。例如
%%capture
print('Hello')
这只是丢弃输出,但可以使用%%capture
魔法将输出保存到变量 - consult the docs
答案 2 :(得分:1)
以下是Dataquest — 28 Jupyter Notebook tips, tricks, and shortcuts帖子的另一个例子:
# 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!
因此它似乎会抑制通常会显示在终端中的语句,而不是“内联”类型,如图。