recently I switched from Spyder to VScode and I miss getting the output of python scripts in console. By that I mean: Let's say I have a script as follow:
x = []
def append_func(x):
for i in range(10):
x.append(i)
return x
y = append_func(x)
and when I ran that script in Spyder, x
would be generated, append_func
would be declared and y
would be generated as well. Then in console (outside of the script) I would write:
sum(y)
len(x)
len(y)
and get informations that may interest me after running the script.
So I would like play with my variables that were generated inside the script without editing the script and rerunning it. Similar functionality is in Matlab - whenever we run the script, all of the variables and functions defined in a script are accessible in console, so we can transform/calculate/reuse them, check how some variables look like or what are their types, (...). It's very handy when the scripts has kinda long execution time and we want to check some statistics of variables we didn't think about before.
Is such functionality in VS Code?
Screen from Spyder. As we can see x
and y
got saved into memory and can be used in the console:
#%%
, See the docshift-enter