ipython—强制在任何光标位置执行表达式
我有IPython 5.3.0,当我处于表达式中间时(光标被标记为<代码> <代码>),例如:ipython—强制在任何光标位置执行表达式,python,terminal,ipython,Python,Terminal,Ipython,我有IPython 5.3.0,当我处于表达式中间时(光标被标记为 ),例如: In [69]: x = np.arange(<cursor>1, 21, 2).reshape(2, 5) In [69]: x = np.<cursor>arange(1, 21, 2).reshape(2, 5) 但当光标位于其他位置时,例如: In [69]: x = np.arange(<cursor>1, 21, 2).reshape(2, 5) In [69
In [69]: x = np.arange(<cursor>1, 21, 2).reshape(2, 5)
In [69]: x = np.<cursor>arange(1, 21, 2).reshape(2, 5)
但当光标位于其他位置时,例如:
In [69]: x = np.arange(<cursor>1, 21, 2).reshape(2, 5)
In [69]: x = np.<cursor>arange(1, 21, 2).reshape(2, 5)
[69]中的:x=np.arange(1,21,2)。重塑(2,5)
它执行表达式
哪个键盘快捷键强制执行表达式而不考虑光标位置
我尝试了CTRL+ENTER或SHIFT+ENTER,但第一个示例中没有一个可用。。早些时候,没有办法不修补,但有一个简单的解决办法
以下是IPython/terminal/shortcuts.py
中5.4.1
的相关逻辑。第一个链接上带有注释的片段是修复
def newline_or_execute_outer(shell):
def newline_or_execute(event):
"""When the user presses return, insert a newline or execute the code."""
b = event.current_buffer
d = b.document
if b.complete_state:
cc = b.complete_state.current_completion
if cc:
b.apply_completion(cc)
else:
b.cancel_completion()
return
# If there's only one line, treat it as if the cursor is at the end.
# See https://github.com/ipython/ipython/issues/10425
if d.line_count == 1:
check_text = d.text
else:
check_text = d.text[:d.cursor_position]
status, indent = shell.input_splitter.check_complete(check_text + '\n')
if not (d.on_last_line or
d.cursor_position_row >= d.line_count - d.empty_line_count_at_the_end()
):
b.insert_text('\n' + (' ' * (indent or 0)))
return
if (status != 'incomplete') and b.accept_action.is_returnable:
b.accept_action.validate_and_handle(event.cli, b)
else:
b.insert_text('\n' + (' ' * (indent or 0)))
return newline_or_execute
如您所见,该操作取决于与代码标记相关的光标位置
所以,如果您有一个完整的语句,只需在Enter之前按End键即可强制执行