首页 > 解决方案 > ipython 不添加新行

问题描述

考虑 ipython repl:

$ ipython
Python 3.6.8 (default, Aug  7 2019, 17:28:10)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.

[ins] In [1]: x = 2

[ins] In [2]: y = 2

[ins] In [3]: 

相反,考虑普通的python repl:

$ python
Python 3.6.8 (default, Aug  7 2019, 17:28:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 2
>>> y = 2
>>> 

如您所见,ipython repl 添加了许多不必要的(我认为)新行语句,而 python repl 则更加简洁。

有没有办法可以禁用这些新行?(请注意,我知道这一点:https ://ipython.readthedocs.io/en/stable/config/details.html可以更改提示时显示的内容。但是,我找不到禁用选项提示之间的新行)

标签: pythonipython

解决方案


ipython--nosep选项开始。

$ ipython --nosep
Python 3.8.3 | packaged by conda-forge | (default, Jun  1 2020, 17:43:00) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: x = 1                                                                                                                                                                   
In [2]: y = 2                                                                                                                                                                   
In [3]: print(x, y)                                                                                                                                                             
1 2
In [4]:

来自ipython --help

--nosep
    Eliminate all spacing between prompts.

也可以通过设置此配置选项来实现此行为:

c.InteractiveShell.separate_in = ''

推荐阅读