Jae Carr
Jae Carr

Reputation: 1225

Move last command in PyCharm interactive shell to script

I basically want a workflow that goes like this:

I'm working on a script and run into some issues so I:

  1. Move the script to the interactive console (shift+alt+e on Mac)
  2. Run a few queries against my variables to figure things out. This step is over when I find a line of code that works.
  3. Use a keyboard shortcut to add it to the end of the file I have open.
  4. Repeat as necessary until I feel good about just editing the file directly again.

Options I'm aware of (that I don't care for)

  1. Scroll up, copy, paste.
  2. Use shortcut to open up history panel. Select line, copy, close panel, click on script, paste.

I feel it would be a lot smoother for my workflow if I could just hit some key combo and BAM! the last line of code I executed is just put at the bottom of the current file.

Can it be done? Anyone have some insight?

Upvotes: 0

Views: 233

Answers (1)

Alex Hall
Alex Hall

Reputation: 36033

If you've just typed a statement, hit enter, seen that it looks right, and have an empty prompt waiting, you can:

  1. Press the up arrow key to bring back the last statement
  2. Press Cmd+A to select the whole statement
  3. Press Cmd+C to copy

If the whole statement fits on a single line, you can skip step 2: in general if nothing is selected then Cmd+C copies the whole line at the cursor.

The prompt >>> or In[x] will not be copied.

You still have to click in the editor to paste, and I don't see a way around that. But at least for the copying you can save on some mouse movement.

Upvotes: 1

Related Questions