14

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.

1

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer Pavel, ENC is exactly what I'd like to do. I'll try out your suggestion and it will hopefully save me some time. P.S. voted.
The link to the feature request is broken. Does anyone know if this feature was added since, or if there is another feature request somewhere?
I see in Jet Brain's Community Edition of PyCharm IDE, there is a plug in called Relodium that provides Edit and Continue functionality. I can't believe that it's not in VS Code, especially for an interpreted language. It looks like IntelliJ has it for Java but I can't get it to work. I love Edit and Continue and am spoiled by VS 2022.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.