tldr; I wish I could get to a specific program state then halt and then continuing editing the same file and keep adding code to the file using this process iteratively.
Details:
What I often want to do is use the python console or run a specific piece of code in a specific program state. However, I do not know how to get to the program state I need for my code to run the way I want.
Usually what I used to do was run the debugger to a break point (so that I could get into the program state that I want). Then I would use the evaluate expression bar. However that seems really inefficient, especially because the evaluate expression bar is hard to use for multiline stuff and it seems meant for more about a single expression rather than testing the real code you intend to use. If I could instead execute, edit and re-execute cells after running an arbitrary program that isn't necessarily organized in a linear fashion (e.g. jupyter style), that would be ideal.
I know it is possible to execute cells (shift+enter or control+enter) and execute selected code (option+shift+e). However, I don't seem to know how to use those properly so that I can do what I want (specifically get to a program state so to test the code I want). So what I want to do is:
- get to a specific program state that I want
then either
a) run code in the console or python console in that program state b) run code in cells (or selections) in that program state
How do I do that?
Or better stated: 1) get the program state I want 2) test new code (not just expressions)
Another issues I found was that it seem that this might require restructuring my code as jupyter like files...hopefully I can avoid that since refactoring is hard and a lot of times I am using code from other places that is NOT structured like that...
Edit with further clarifications
what I'm most interested though is having the following work flow:
- execute a code and stop at a breakpoint
- then after that break point (and thus specific program state), build the next piece of code ideally in the current file.
for step 2 I'd to use something like the execute selection. If I could get to a program state (say using a break point), then write code after the break point and execute it (e.g. with alt+shift+e) that would be perfect. However, note the crucial point that the next code I am executing after the break point is new code, it's not there yet and I don't know what it is because it depends on the current program state. I know adding new code while in a debug state in vs-code wouldn't work. I just checked and it doesn't work in pycharm either.
I really liked that one could sort of do this with cells in pycharm. If I could get to a program state (e.g. using a break point), then create new code after that (say with a python cell) then keep running the code and keep breaking and building. That could be ideal.
The best seems to copy paste from the debuger console the code I write (which unfortunately end up having >>> from the console) and then re-run the debuger.
I wish I wouldn't have to re-run the debuger and edit the file, the way pycharm cells work.
potential solution: copy paste program states to jupyter
or if I could "drag and drop program states" that would do it. I would always have a jupyter style script open and then "copy paste" the program state from the previous run and then use that in the new cell in the other file.
Cross posted:
- pycharm forum: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009568699-How-do-I-test-arbitrary-code-after-reaching-an-arbitrary-program-state-
- quora: https://www.quora.com/unanswered/How-do-I-test-arbitrary-code-after-reaching-an-arbitrary-program-state-in-PyCharm
- reddit: https://www.reddit.com/r/pycharm/comments/iibijp/how_do_i_test_arbitrary_code_after_reaching_an/
- drag drop program state: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009673520-how-does-one-drag-and-drop-a-program-state-after-a-break-point-