0

I like the way Jupyter extension is built on VSCode, but I haven't get it to run a cell of my choise.

My question is: Is there a way to select which line gets executed or is it always the last in the file?

Right now I just put each output providing cell to separate file and import required features, but quick iterative experiments would be handy just to quickly write on the same file.

1 Answer 1

1

It looks like #%% begins a cell so there are two ways of doing this I think:

#%%
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

#%%
x = np.linspace(0, 20, 100)
plt.plot(x, np.sin(x))
plt.show() 

and you can run each cell separately (or line - wherever you place the #%%) Run cell will pop up above the line you put this on.

Or install code-runner: code-runner. For more info see here: Jupyter-IPython and here Getting Started

EDIT: Just found another way from the last hyperlink:

  • Open a python file
  • Select a line or a block of code
  • From the command palette (cmd+shift+p) select the command Jupyter: Run selection/line
  • The results will be displayed on the right hand side
  • A status bar will appear with the name and status of the kernel
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Why didn't I know about code-runner that can help with other stuff as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.