How can I start an interactive session at breakpoint in VS Code? - python

Above is a typical situation that I encounter. We hit an exception and now would like to get some more details about what went wrong. This is where I wish I could just jump right into an interactive python session and try to run the marked line manually to find out e.g. what the find_many might look like and if it actually does have a select method. How can I do this?

I think the Debug Console is what you are looking for. Press F1 and type debug console if you do not find the window.

You can use shift+enter or manual select the option like the following picture with the right mouse button.

Related

message that pops up while writing python code on vscode

I am not sure what it is actually called. I am a beginner. I am learning python and using VS Code as my code editor. But when I write codes the message in the red circle highlighted in the screenshot pops up. It's kind of annoying.
Can someone please help me with it? I don't know what it is called and would like to turn it off.
That pop up just shows the structure of the function you are using. It includes parameter hints.
In the image it is showing the structure of print function. It's a useful feature to be honest.
Press esc to cancel out of an individual popup, or set"editor.parameterHints.enabled": false to disable it entirely.
So, that box you have there is the documentation of the method you are calling. In this case, print(). It's actually quite useful. It'll give you a quick description of the parameters that you can pass into the function. For more confusing functions, the auto-documentation is a must have. But, of course, it is up to you.
You can disable it by setting "editor.parameterHints.enabled" to false in your .json
This is a function provided by VS Code to display information such as method parameters. You can turn it off in settings.
Click the gear icon in the lower left corner and select Settings,
then search for parameterhints, and uncheck the options in the picture.
In addition, as mentioned above, you can also add the following configuration to the settings.json file to achieve the same effect.
"editor.parameterHints.enabled": false

Why I can't able to do step in, step out in pycharm?

I am not able to click(I can say it's diabled) step in, step out, step over option in pycharm debugger
I don't know if this is exactly what is causing your issues but here is one possibility:
All debugging options are grayed out in the menu if your cursor is on an empty line or a line that is a comment. Try putting your cursor on an actual line with code. The "Toggle Line Breakpoint" option in the "Run" menu should now become active. After starting the script with "Run -> Debug", the breakpoint will be triggered (assuming the code reaches it) and the other debug options such as "Step over" become available.
As mentioned in this answer: https://stackoverflow.com/a/48665161/2891209
Depending on what you're trying to debug it is possible for step-in to not show you code which isn't pure python. Pycharm will do the best it can of course, but if the function you're trying to debug isn't native python be prepared for anything...
If you're trying to step into a python wrapped C library function
Sometimes the debugger will skip over that code completely.
Sometimes you can walk the frames but the editor can't show you lines of code.
Sometimes you'll be able to step into an empty skeleton of a function.
It really depends on how the library was created.

how to clear the screen in pycharm

I know these are questions: this and this and this. I have tried all of these methods in pycharm, but they either a) not work or b) I get a weird character on my screen, that looks like a 0 with diagonal line going through it. I can't copy it for some reason, so I can't show you.
For instance this:
import os
from time import sleep
print("lots of text")
sleep(5)
os.system('cls')
What should happen in the above is tht the message should be displayed for 5 seconds then disappear, but all I get is that weird character... In contrast when I ran my python program from command line, it worked as expected i.e. the screen cleared. I am very confused.
So my questions are:
Why don't any of them work in pycharm?
What does work in pycharm?
Ok, so, I have been having this problem as well — after scouring the internet, the os commands work BUT you need to enable the terminal emulator.
In the PyCharm toolbar, click Run, Edit Configurations, and the toggle for "Emulate Terminal in Output Console" should be under Execution in the pop up. Emulate Terminal toggle
I had to get help from the PyCharm team on this one, so here's to them responding at lightning speed.
Answer
The cls command doesn't work on a standard pycharm project because it is an IDE and certain os commands don't work in the same way it would with the windows command line.
There is currently no way to clear the console output in PyCharm, other than to manually do it by using the cls command through the terminal in PyCharm or through a keyboard shortcut set through the pycharm preferences menu. You can try to emulate a keyboard shortcut, but this would be difficult, and unless you absolutely need it, I would not recommend clearing the terminal output after a program is run.
References and Additional Links
https://teamtreehouse.com/community/clear-screen-for-pycharm-as-if-it-were-on-console-or-cmd
I don't know in which version of PyCharm this was introduced. I guess it must have been after this question was asked.
The way to clear the PyCharm Python Console is by using the context menu. Right mouse click in the upper part of the console (where the lines with >>> prompts are closer together) and select Clear All.
Alse see this PyCharm Support Community article.
Incidentally, none of the questions linked to in the OP's original post relate to PyCharm and do not answer the OP's question.
cls only temporarily clears it. Next command brings back all previous messages. The best option is to right click on the Terminal and choose Clear Buffer

Python IDLE. Auto-complete/Show completions not working

IDLE is being very dodgy as to when it will actually show an Auto-complete menu. As of late it hasn't been working at all, or, more specifically, only works during an interactive session.
I've been using Code Blocks for C, and have gotten really used to the very nice auto-complete features, so it's a bit frustrating not having them -- especially while trying to learn a new frame work and what class is associated with which methods, etc, etc..
Is there an easy fix to get IDLE auto-complete working again? I'm using python version 2.7.
Is there perhaps a simple editor I should look into? I've tried Vim, which was a little too heavy for my simple needs, Ninja, which I couldn't get to work for anything, and Sublime text 2, which I couldn't get my wxpython stuff to play with. What would a nice option be? Anything similar to Code Blocks would be cool, although, I'd be perfectly happy with IDLE if it would consistently work!
REQUESTED CLARIFICATION:
OK, so it seems I may have some of my terminology backwards. By non-interactive, I mean, for instance, right clicking on a python file and selecting "edit with IDLE". This brings up what I guess could be described as a text editor. You can enter all you code here. Once ready, you then hit F5, or select Run, and it launches (what I've been referring to as) the interactive terminal. It's here that you can type in code, press return, and instantly have that code evaluated.
What my question is referring to it the former, the part of IDLE where you edit the code. Sometimes while typing, after a . it will display the available methods, or after an open parenthesis it'll give hints as to the values expected. but the thing is, sometimes it does these things, sometimes it doesn't.
The only thing i found so far is that if an editing session of IDLE is connected with python shell (called "interactive mode" in the question, i.e. after an attempt to run the edited script) then "non-interactive" IDLE can autocomplete based on values in interactive window. For example, if I type
a = [];
a.appen
and then hit < Tab > it will do nothing, but if I previously type
a = []
in corresponding python shell, IDLE will autocomplete correctly.
So my only suggestion is import same modules with same names in python shell window in order to make them "visible" for non-interactive IDLE editor.
I had the same problem with IDLE, because I want to learn Qt and therefore autocompletion is very useful.
As it says in the settings of IDLE, you can trigger the autocomplete with "Control + Space", e.g. after a "QtGui.". Then a menu opens where you can arrow-scroll through the entries.
using the 'IDLE Editor window', you need to save and execute your code first.
The application running, turn back to the Editor window to use the auto-completion.
In my case, I had to open Options menu -> Extensions tab on the editor and look to make sure AutoComplete and other relevant options were enabled. They actually were, but by just clicking on 'Apply' even though I dint have to change anything did the trick for me.
Sometimes it has to do with the time you have to wait to get a suggestions.
When you go to options > extensions > general at completions popup wait you can change it to about 500ms.
In my case it was 2000ms by default.

debug a big loop in eclipse

I am debugging a Python program in Eclipse.
I have a breakpoint in a big loop and I expect the problem to occur in the (1000+)th round. How can I reach that ASAP instead of clicking resume 1000 times?
You want to set a conditional breakpoint. Read through the link I provided for an explanation and example in python.
Ctrl-R is the equivalent to placing a breakpoint on the cursor's line and clicking the "Resume" button, except that it doesn't litter your system with unnecessary breakpoints.
Is this what you are looking for?
Take a look at this: http://www.clear.rice.edu/comp310/Eclipse/debugging.html

Categories

Resources