用于抑制输出的分号在 IPython 中不起作用
在 IPython Tips & 的文档中Tricks,它说在命令末尾放置一个分号(;)以抑制其输出。这在我的情况下似乎不起作用,即使是
print('Hello');
输出
Hello
我对输出抑制有错误的想法还是这是一个错误?在 PuDB 中工作时,这尤其烦人,因为当我按“下一步”时,它会在我的情况下可怕地闪烁”或“步入”。
PS:输出既不在我的 Ubuntu IPython 0.10 上,也不在 OS X v10.7 (狮子)IPython 0.11 被压制。尽管闪烁问题在 OS X 中更严重,可能是因为 item2。
In the documentation at IPython Tips & Tricks, it says to put a semicolon (;) at the end of a command to suppress its output. This does not seem to work in my case as even a
print('Hello');
outputs
Hello
Do I have the wrong idea of output suppression or is this a bug? This is especially annoying when working in PuDB, as it flashes horribly in my case as I press 'next' or 'step into'.
P.S.: The output is neither on my Ubuntu IPython 0.10 nor OS X v10.7 (Lion) IPython 0.11 suppressed. Although the flashing issue is worse in OS X, probably because of item2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试类似
1 + 1;
。如果没有分号,它应该通过打印结果来为您提供有关结果的反馈(由repr
格式化,尽管在整数的情况下并不重要) - 我认为这个输出应该是压制。shell 不会(也不应该)抑制对
sys.stdout
引用的文件的写入(这本质上是print
所做的)。这是完全不同的事情,不是 shell 的工作。Try something like
1 + 1;
. Without the semicolon, it should give you feedback about the result by printing it (formatted byrepr
, though it doesn't matter in the case of integers) - I assume that it's this output that's supposed to be suppressed.The shell doesn't (and shouldn't) suppress writing to the file that happens to be referenced by
sys.stdout
(which is essentially whatprint
does). This is an entirely different matter, and not the job of the shell.添加
%%capture
作为单元格的第一行。例如,这只是丢弃输出,但可以使用
%%capture
魔法将输出保存到变量中 - 查阅文档。Add
%%capture
as the first line of the cell. For example,This simply discards the output, but the
%%capture
magic can be used to save the output to a variable—consult the documentation.这是 Dataquest 中的另一个示例 - 28 个 Jupyter Notebook 提示、技巧和快捷方式帖子:
以及“有效”分号抑制的示例:
因此它似乎抑制了通常显示在终端中的for语句,但不是“内联”类型,如情节。
Here's another example from the Dataquest — 28 Jupyter Notebook tips, tricks, and shortcuts post:
And an example of a "working" semicolon suppression:
So it appears to suppress for statements that would normally show up in the terminal, but not "inline" types, like plots.