How to keep the python session on in vscode?

I am using vscode and windows 10. I can open a python script and run it. Generally, it is like this

PS C:\Users\jmzhang> & D:/Anaconda/python.exe c:/Users/jmzhang/Downloads/aklt-master/aklt.py
Closed chain:
[-2.69 -2.34 -2.34 -1.63 -1.63 -1.49 -1.25 -1.25 -1.24 -1.24]
Open chain:
[-2.03 -1.97 -1.97 -1.87 -1.4  -1.4  -1.19 -1.19 -1.17 -1.17]
PS C:\Users\jmzhang> 

Once the script is over, the session is over too. I cannot access the workspace to see the values of the variables.

How to config vscode so that once a script is invoked, the python session is there forever?

If you want to introspect variables while your script runs, I recommend VS Code’s debugging tool. If you want an interactive session and a plain old REPL shell isn’t enough, I recommend VS Code’s notebook feature.

1 Like

If you used your own command line window, you could just pass the -i flag to Python:

C:\Users\jmzhang> D:/Anaconda/python.exe -i c:/Users/jmzhang/Downloads/aklt-master/aklt.py

(Incidentally, the Downloads folder is probably not a very good place to keep code that you’re developing…)

You should be able to type something like that directly into the Terminal window in VSCode. Maybe there is a way to configure it to do that automatically, but I don’t know how (I don’t use any IDE). It sounds like more trouble than it’s worth; you’d have to close the REPL explicitly every time before you could re-run the script (otherwise, the IDE would be sending that command line into the REPL, which would fail because it isn’t valid Python code).

1 Like