Pycharm:只运行我的 Python 文件的一部分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23441657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pycharm: run only part of my Python file
提问by FrankTheTank
Is it possible to run only a part of a program in PyCharm?
是否可以在 PyCharm 中只运行程序的一部分?
In other editors there is something like a cell which I can run, but I can't find such an option in PyCharm?
在其他编辑器中,我可以运行类似单元格的东西,但在 PyCharm 中找不到这样的选项?
If this function doesn't exist it would be a huge drawback for me... Because for my data analysis I very often only need to run the last few lines of my code.
如果这个函数不存在,那对我来说将是一个巨大的缺点......因为对于我的数据分析,我经常只需要运行我的代码的最后几行。
回答by PyTony
You can select a code snippet and use right click menu to choose the action "Execute Selection in console".
您可以选择一个代码片段并使用右键单击菜单选择“在控制台中执行选择”操作。
回答by Games Brainiac
You can set a breakpoint, and then just open the debug console. So, the first thing you need to turn on your debug console:
可以设置断点,然后直接打开调试控制台。因此,您需要打开调试控制台的第一件事:
After you've enabled, set a break-point to where you want it to:
启用后,将断点设置到您想要的位置:
After you're done setting the break-point:
设置断点后:
Once that has been completed:
一旦完成:
回答by Wisienkas
回答by Willian Adamczyk
I found out an easier way.
我发现了一个更简单的方法。
- go to File -> Settings -> Keymap
- Search for
Execute Selection in Console
and reassign it to a new shortcut, like Crl+Enter.
- 转到文件 -> 设置 -> 键盘映射
- 搜索
Execute Selection in Console
并将其重新分配给新的快捷方式,例如Crl+Enter.
This is the same shortcut to the same action in Spyder and R-Studio.
这是 Spyder 和 R-Studio 中相同操作的相同快捷方式。
回答by floatsd
- Go to File >> Settings >> Plugins and install the plugin
PyCharm cell mode
- Go to File >> Settings >> Appearance & Behavior >> Keymap and assign your keyboard shortcuts for
Run Cell
andRun Cell and go to next
- 转到文件>>设置>>插件并安装插件
PyCharm cell mode
- 转到文件>>设置>>外观和行为>>键盘映射并为
Run Cell
和分配键盘快捷键Run Cell and go to next
A cell is delimited by ##
单元格由 ## 分隔
Refhttps://plugins.jetbrains.com/plugin/7858-pycharm-cell-mode
参考https://plugins.jetbrains.com/plugin/7858-pycharm-cell-mode