简体   繁体   中英

How to select cell to run when using Jupyter when running it in VSCode?

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.

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

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