禁止* Out [] * IPython打印,但不禁止其他打印

时间:2019-01-09 11:18:46

标签: command-line ipython

我正在IPyton中运行一些代码::

jrlab@jrlab-T150s:~$ ipython

In [1]: from IPython import get_ipython
   ...: ipython = get_ipython()
   ...: 
   ...: code = """
   ...: import matplotlib.pyplot as plt
   ...: 
   ...: print("bla")
   ...: 
   ...: plt.figure()
   ...: """
   ...: res = ipython.run_cell(code)
   ...: 
bla
Out[1]: <Figure size 640x480 with 0 Axes>

如何禁用Out [1]打印,而不禁用 print 语句命令的打印?

1 个答案:

答案 0 :(得分:1)

None未打印为输出。因此,只需将; None附加到您希望抑制其输出的任何行即可:

In [1]: 1+2                                                                                                                                        
Out[1]: 3

In [2]: 1+2; None                                                                                                                                  

In [3]: