My question may seem bizarre.
I am debugging a program in python with portable python, pyscripter.
Is it possible to ask pyscripter to do this? :
"Run the program until my_variable 's value become equal to 10, then stop at that point, and let me debug it line by line (using F7 or F8)"
I want some sort of breakpoint that activates when a variable gets some specific value.
Yes, PyScripter can do this. It is called conditional breakpoint.
Put a breakpoint, open Breakpoints tab, right-click on your breakpoint to bring context menu where you can add a condition (python expression)
Related
I am used to debugging in RStudio. Using R I simply use the command: debug(my_function), then run the code and automatically the script debugs at my_function.
Now I am using Python in VS Code, I see debugging is possible by setting breakpoints visually using the red dots. However I need to debug a function without actually knowing where this function is stated. So my question is can I debug a specific function in VS Code using a command?
I hope to use something like this command line -> debug(my_function)
Thanks!
It looks impossible for now, I have submitted a feature request on GitHub.
Maybe you can try to copy the function into an isolated python file to debug it for now.
They are called Function Breakpoints
A function breakpoint is created by pressing the + button in the BREAKPOINTS section header and entering the function name. Function breakpoints are shown with a red triangle in the BREAKPOINTS section.
I'm debugging a python script, and I want to watch a variable and get notified whenever its value changes.
Is there a way to do this in pudb?
You can't simply ask for notification any time a value changes (that I'm aware of).
However, you can set both watch expressions and conditional breakpoints which should provide the capability that you're looking for.
First, go to the variable list (shift+V), then N to add a new watch. Enter in whatever variable you want to watch.
Now set a breakpoint at the places that your value can change - back to the main window ←, then find the lines and hit B. Then let your program run to that line or until your variable is defined.
Then shift+B to select the breakpoints window. Press enter to edit the breakpoint. Add a conditional expression - since your value should be set by now, you can see the value in your watch list. A simple <variable> != <current value> should do. Or you can enter a specific criteria.
Now ← back to the main window and let your program continue. When your conditional is true at that breakpoint, your program will stop and you will see the value in your watch list.
For an example, see the following screencast:
Context: using Enthought's Canopy Version: 1.7.4.3348 (64 bit) on Windows 10.
Typing into the python shell, errors produce a "...:" prompt, which I can then not break out of. Hitting enter and trying other ideas sadly leads to a repeat of the same prompt. How to break out of this mode, and get on with debugging?
EDITED, see bottom of answer
The key point to understand is that when IPython prompts you with ..., it is because you are in the middle of typing a multi-line statement (whether that was your intention or not). Typically this is because on some previous line, you typed a left parenthesis (or bracket), or a triple-quote-mark, etc and IPython is waiting for you to complete your statement with a right parenthesis or matching triple-quote, etc.
So what you probably want to do is simply to erase your partially entered statement. The easiest way to do this, assuming that your cursor is already at the end of the last line in your multi-line statement, is just to press and hold the backspace key until your statement is all erased. Slightly quicker is to do the same with Ctrl+Backspace, which erases a word at a time instead of a character at a time. After you've erased all the garbage, press Enter, not actually needed but it will make you feel better, to convince yourself that everything is back to normal.
(BTW, the fact that you were actually in the middle of typing a single long statement also explains why typing "quit" does nothing; you are not really typing a "quit" command, but just typing the additional letters "quit" into the middle of your already too-long and erroneous command, whatever that might be, which makes it even longer and more erroneous!
As a further side note -- quit is actually not very useful in Canopy's IPython panel, because it just closes the panel but doesn't really close down IPython; if you reopen the panel from the View menu, it is still just as you left it. If you really want to restart IPython (clear all your variables and imports), do it with the "Restart kernel" command in Canopy's Run menu.)
EDIT:
OP's screen shots, sent privately, showed that Autodebug mode was on (this is the bulls-eye-like icon on the toolbar.) The solution was to toggle off Autodebug.
Background: Autodebug hooks into the channel between Canopy's IPython (QtConsole) front end, and the IPython kernel back end. If autodebug is left on, some problems can break this channel. This should be improved in Canopy 2.0, currently in alpha internally.
Try pressing Ctrl + D, that help in coming out of the console panel.
since yesterday PyCharm 2016.3 won't accept selected lines from the list of code completion:
If I hit enter, a new line will be set into the editor rather than the selected line of the popup window. Is there any setting for this behaviour? Until now I couldn't find anything.
I noticed on a few occasions the GUI going somehow off-rails, including in ways similar to the one described. I couldn't determine a pattern in the occurences. Just closing and re-opening the project didn't always help.
What worked pretty reliably for me in the end was exiting PyCharm (giving it ample time to finish), making sure no related java processes remains active (running on Linux, in some cases I had to manually kill such processes when it became clear they're not going away by themselves) and then re-starting the IDE.
I found the current keymap for code completion by chance. This is set via:
Settings > Keymap > Code > Completion > Basic
I've never used an IDE so probably my problem is really basic.
When I start the debug mode, it shows me only this empty screen
pic
How can I let it start correctly?
You need to add breakpoints by clicking on the sidebar near the line count.
Then, when you will start a debugging session the execution of the code will stop at your breakpoint, you can then uses the multiple controls to navigate in your code.
You will also see the variables related to your code.