如何在给定选项卡时阻止ipython关闭函数定义

如何在给定选项卡时阻止ipython关闭函数定义,ipython,Ipython,我经常使用将python文本直接发送到控制台的工作流 使用默认Python控制台,当我输入一个具有空行的函数时,如果在空白行上保留一个选项卡,则控制台将不会关闭函数定义。例如: $ python Python 3.8.2 (default, Jul 16 2020, 14:00:26) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license&qu

我经常使用将python文本直接发送到控制台的工作流

使用默认Python控制台,当我输入一个具有空行的函数时,如果在空白行上保留一个选项卡,则控制台将不会关闭函数定义。例如:

$ python
Python 3.8.2 (default, Jul 16 2020, 14:00:26)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def test(i):
...     print(i)
...     
...     print(i)
...
>>>
$ ipython
Python 3.8.2 (default, Jul 16 2020, 14:00:26)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.17.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: def test(i):
   ...:     print(i)
   ...:     

In [2]:     print(i)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-3b184248ad5a> in <module>
----> 1 print(i)

NameError: name 'i' is not defined

(注意函数
test
第二行的空格)

但是,当我尝试对ipython控制台执行相同操作时,控制台会忽略该选项卡并关闭函数定义。例如:

$ python
Python 3.8.2 (default, Jul 16 2020, 14:00:26)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def test(i):
...     print(i)
...     
...     print(i)
...
>>>
$ ipython
Python 3.8.2 (default, Jul 16 2020, 14:00:26)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.17.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: def test(i):
   ...:     print(i)
   ...:     

In [2]:     print(i)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-3b184248ad5a> in <module>
----> 1 print(i)

NameError: name 'i' is not defined

$ipython
Python 3.8.2(默认值,2020年7月16日,14:00:26)
有关详细信息,请键入“版权”、“信用”或“许可证”
IPython 7.17.0——一种增强的交互式Python。键入“?”以获取帮助。
在[1]中:def测试(i):
…:打印(i)
...:     
在[2]中:打印(i)
---------------------------------------------------------------------------
NameError回溯(最近一次呼叫上次)
在里面
---->1份印刷品(一)
名称错误:未定义名称“i”
是否有任何方法可以将一个函数传递到ipython控制台,并使其在空行(如果这些行有制表符)上不关闭