简体   繁体   English

如何在 Spyder 4 中运行选定的行?

[英]How can I run selected lines in Spyder 4?

In previous versions of Spyder, you can select lines in the editor, and only run those selected lines.在以前版本的 Spyder 中,您可以在编辑器中选择行,并且只运行那些选择的行。

In Spyder 4, when you select lines and press Ctrl + Enter it executes runcell(0, '/your/dir/file.py') which runs the whole code.在 Spyder 4 中,当您选择行并按Ctrl + Enter时,它会执行runcell(0, '/your/dir/file.py')来运行整个代码。

How can I run just the lines which I have selected?我怎样才能只运行我选择的行?

The hotkey for running a the line at which the cursor is, or the currently selected lines in Spyder 4 is F9 .运行光标所在行或 Spyder 4 中当前选定行的热键是F9 Ctrl + Enter will run the current cell . Ctrl + Enter将运行当前单元格 You can read more about cells in Spyder here .您可以在此处阅读有关 Spyder 中单元格的更多信息。 Basically, these are blocks of code that can be defined in the editor using a specific syntax within the code, and can be run independently by Spyder and other IDEs.基本上,这些是可以在编辑器中使用代码中的特定语法定义的代码块,并且可以由 Spyder 和其他 IDE 独立运行。

Incidentally, Ctrl + Enter is the keyboard shortcut for running the current line in R Studio, not Spyder, which may be where you got it confused.顺便说一句, Ctrl + Enter是在 R Studio 中运行当前行的键盘快捷键,而不是 Spyder,这可能是您感到困惑的地方。

In Spyder 4.0.1, the keyboard shortcut for 'run cell' is set to Ctrl+Return but for 'run selection' it is set to F9.在 Spyder 4.0.1 中,“运行单元格”的键盘快捷键设置为 Ctrl+Return,但“运行选择”设置为 F9。 You can use F9 to run a selection or if you prefer to use Ctrl+Return, you can go to Tools -> Preferences -> Keyboard shortcuts.您可以使用 F9 运行选择,或者如果您更喜欢使用 Ctrl+Return,您可以转到工具 -> 首选项 -> 键盘快捷键。 Search for 'run selection', double click and set Ctrl+Return as the 'New shortcut'搜索“运行选择”,双击并将 Ctrl+Return 设置为“新建快捷方式”

In Spyder, you can organize your code as runnable cells.在 Spyder 中,您可以将代码组织为可运行的单元格。

Use the the pattern # In[] or #%% to define the start of a cell.使用模式# In[]#%%来定义单元格的开始。 You can also have child cells by adding additional percent signs % .您还可以通过添加额外的百分号%来创建子单元格。

Spyder iPython 细胞

In Spyder 4 the keyboard shortcut to run the highlighted lines of code is F9 .在 Spyder 4 中,运行突出显示的代码行的键盘快捷键是F9 and if you want to use any other shortcut then you can change it from TOOLS>>PREFERENCES>>KEYBOARD SHORTCUTS then double click on any shortcut you want to change and change with your shortcut.如果您想使用任何其他快捷方式,则可以从工具>>首选项>>键盘快捷方式更改它,然后双击要更改的任何快捷方式并使用快捷方式进行更改。 but be very careful if you used the same shortcut that is used for any other work then for that it will remove.但要非常小心,如果您使用与任何其他工作相同的快捷方式,那么它将被删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM