I have started using VS with Python and I was expecting to have similar features as in R. What I need is to be able to edit and execute line by line ("Sent to Interactive" command) as well as see current values of the defined variables? This last item is missing and I am not able to find any way to display values of all current variables in Local, Watch or any other window while doing interactive Edit Execute?
(There are similar question at StackOverflow but couldn't find answer to this particular one)
There isn't any obvious way to inspect variables in the current context in Interactive Window in PTVS, unfortunately. We are aware of this deficiency, and would like to fix it in future versions.
In the meantime, there are some workarounds that may be "good enough". The most obvious one is to use dir()
to dump the names of the locals (and you can turn it into a one-liner dict comprehension to dump the values alongside with the names).
Alternatively, you can attach PTVS debugger to the Python process backing the Interactive by using the $attach
magic command. This works the same as a regular debugging session, and so you won't see the locals until you somehow pause the process. The easiest way to do so is to cause an exception to be raised in the REPL, e.g. simply by typing raise Exception
- then you'll be paused in the right frame, and can see all your variables in Locals and edit them as usual; of course, you'll have to unpause the process before you can use the REPL again.