简体   繁体   中英

Pycharm: run only part of my Python file

Is it possible to run only a part of a program in PyCharm?

In other editors there is something like a cell which I can run, but I can't find such an option in 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.

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 .

This is the same shortcut to the same action in Spyder and R-Studio.

Pycharm shortcut for running "Selection" in the console is ALT + SHIFT + e

For this to work properly, you'll have to run everything this way.

在此处输入图片说明

您可以选择一个代码片段并使用右键单击菜单选择“在控制台中执行选择”操作。

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:

在此处输入图片说明

  1. Go to File >> Settings >> Plugins and install the plugin PyCharm cell mode
  2. Go to File >> Settings >> Appearance & Behavior >> Keymap and assign your keyboard shortcuts for Run Cell and Run Cell and go to next

A cell is delimited by ##

Ref https://plugins.jetbrains.com/plugin/7858-pycharm-cell-mode

There is an option that you can run jupyter notebook file and its cells in pycharm. For more information visit Run and debug Jupyter notebook code cells in pycharm .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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