Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit-and-continue while debugging under Python Visual Studio?

I often find when debugging that I have a small mistake in my code i.e. misspelling of a variable. It is very time consuming to have to then start the program again from the beginning.

Is it possible to correct this mistake and then have the program carry on running from where it left off? Specifically, I have been coding in Python using Visual Studio as an IDE.

like image 944
rwolst Avatar asked Jul 12 '13 16:07

rwolst


1 Answers

Since you are talking about Python in Visual Studio context, I'm assuming you're using Python Tools for Visual Studio (PTVS).

The feature that you're referring to is often known as "Edit and Continue" (ENC) in VS, since that's what it was called for C# and VB originally. Unfortunately, PTVS does not support it yet, but there is a feature request tracking that - vote for it!

Some limited form of ENC is possible with the use of Python Debug Interactive window, aka Debug REPL (available in Debug -> Windows). This allows you to break on a breakpoint, and manipulate state of your process in a REPL-like way - including defining new functions or redefining existing ones, for example. This is not quite as fine-grained, since you would have to rewrite the entire function body even if you just want to change a single identifier (though you can just copy/paste the definition from the editor into REPL and then edit it there). It also doesn't cover all the same scenarios - e.g. if the function you redefine is currently running, it will still be using the original definition; also, if anyone stashed away the reference to the original function, that will not be affected. Still, in some cases, you may find it useful.

like image 140
Pavel Minaev Avatar answered Nov 16 '22 00:11

Pavel Minaev