Multi-line editing broken in IPython 7.0.1

2019-02-23 18:41发布

I'm using IPython in zsh shell and I'm having a trouble defining a function with multiple lines.

For example, in the original Python shell, I can define a function f like this:

>>> def f(x):
...     a = x + 1
...     return a
... 
>>>

When I did it in IPython, the defination ends immediately when The line 'a = x + 1' ends. It looks like this:

In [4]: def f(x): 
   ...:     a = x + 1                                                                                                                              

In [5]:   

How can I fix it by changing some configuration or installing another version of IPython?

My version of Python and IPython:

Python 3.5.6 |Anaconda, Inc.|  
Type 'copyright', 'credits' or 'license' for more information
IPython 7.0.1 -- An enhanced Interactive Python. Type '?' for help.

1条回答
萌系小妹纸
2楼-- · 2019-02-23 19:13

It's a known bug (see also this).

As it's clear from the issues I've referenced, it's not a bug with the Anaconda distribution but something that slipped into the 7.0 release of IPython.

Matthias Bussonier suggested to use C-o (that is Control o) as a stop gap measure. C-o opens new blank lines below the current line that you can reach and edit using the arrow keys — it's not a very satisfactory solution but for now there is no other solution (except, of course, downgrading IPython to 6.x).

Concluding, use C-o to open new lines and wait for a bug fix or downgrade to IPython 6.x.


Additional Info

Carlos Cordoba, one of the Spyder maintainers, in a comment to an answer of mine says that also the qtconsole is affected by this bug...

Moreover the bug, fixed in the IPython 7.1 shell, is still present in the same version of qtconsole and the stop-gap measure I've mentioned (Ctrl-o to open a line below the current one) does not work in qtconsole.

查看更多
登录 后发表回答