I'm starting to use pudb for Python debugging. It comes up fine, and I can step through, and it stops at breakpoints I put into code with pudb.set_trace(). So far so good. The main problem I'm having is this:
If I hit ^X to get to the command-line pane, I can type executable lines or variable names, like running interactive Python, but the slightest typo (or experiment in search of other commands, or request for help()) lands me in a state I can't recover from. Even Control-c (as claimed at https://docs.python.org/2/tutorial/appendix.html#tut-interac) just shows up as "^C" and does nothing.
For example, if I type "help()", it prints some Python (not pudb) help, redisplays "help()" in yellow, and then I'm dead in the water. Backspace won't affect the "help()" that's displayed, and ^H just gets displayed as caret + H -- until I hit return, when it seems to be appended to "help()" as literal backspaces, since I can make part of all of "help()" disappear. I can type anything after "help()", but I always get:
SyntaxError: unexpected EOF while parsing
followed by a redisplay of what I had typed. How do I "clear" this state and get back to the normal command line, short of quitting my terminal program?
Using Terminal on Mac OS X 10.9.5, though I can also try Linux.
Your description points not to a problem with pudb but rather to a problem with behaviour of Backspace on the Terminal you're using.
Please try changing this behaviour so it's sending the proper Backspace. This could be helpful: http://fredericiana.com/2006/10/16/fixing-backspace-and-delete-for-ssh-in-os-xs-terminalapp/
Then, you should be able to enter pudb's full screen Python interpreter by '!' and leave it by Control-D.
A "small" Python command line inside pudb's interface can be accessed by Control-X and you can leave it by Control-X. In this one you have three other shortcuts which also let you manipulate the command line: Control-V - insert new line and Control-N/Control-P to browse command line history. If any of these is not working it's rather an issue with the way the Terminal treats these shortcuts and not in the way pudb does.
Related
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 am looking for a simple way to clear the terminal scrollback from within a Python script. I am aware of os.system('clear'), however this only prints new lines, hiding the scrollback history from view, not deleting it. Is there a way to do this? Thanks!
Use the following in Python 2:
>>> print '\033c',
and the following in Python 3:
>>> print('\033c', end=None)
These statements output Escc, which is the VT100 escape sequence for "Reset Device".
As noted, one can use a hardware reset on the terminal, i.e., \033c. That works, but even for a terminal emulator can have some unwanted effects such as resetting colors.
If you were using xterm, that has a specific control sequence \033[3J which does this (see XTerm Control Sequences, i.e., "Ps = 3 -> Erase Saved Lines (xterm)."). OSX Terminal apparently does not implement that, as noted below.
For OSX-specific behavior, this question was asked before, e.g.,
How do I reset the scrollback in the terminal via a shell command? which suggests using the osascript utility. Interestingly enough, one of the alternatives suggested is \033[3J, but that does nothing on my Mac.
How to clear previous output in Terminal in Mac OS X?, with similar responses. One (not the most popular) answer points out a problem with the simplest use of osascript, that it may clear the wrong window, and supplies a different answer from the following:
How do I reset the scrollback in the terminal via a shell command?, e.g.,
osascript -e 'if application "Terminal" is frontmost then tell application "System Events" to keystroke "k" using command down'
(I have tested the last, and it works for me).
Sometime I look back at my terminal when there is a python script running and the console output has frozen, then I right-click on the terminal and the console output (printing to screen) beings again.
Its a bit disconcerting because sometimes I think my script has broken.
Do others also experience this? Anybody know a fix?
Thanks in advance for any responses
If it's intermittent with all other factors being unchanged, it sounds like you've inadvertently selected some text in the PowerShell console and it's halted updating output so that you can do something with it.
Next time, be careful to look to see if you have something selected before clicking.
I agree with #alroc's suggestion; i.e. the cause could be accidentally clicking on the console.
A solution to prevent this is to right click on the powershell console window's title bar, select properties, uncheck Quick Edit Mode, then click OK. This disables some features (i.e. copy by select & enter, paste by right click), but means if you accidentally click on the screen it does no harm.
Another solution's to simply press escape (or right click in the script's window) if the script's taking a while - generally that'll do no harm (i.e. it won't terminate your script), but it will exit the edit session, allowing the script to resume if it had been paused due to edit mode.
To play with these, run the below script, then click on the screen whilst it's running (this script just outputs a bunch of numbers).
1..99999999
To terminate the script completely, press ctrl+c.
I am editing a python script that I wrote a while ago, using aquamacs on Mac lion.
Whichever letter or number I type is being interpreted as "enter" (that is, I hit "g" for example, my text is dissrupted and a newline appears, but "g" does not appear). Restarting aquamacs, the terminal out of which I run it, or the whole computer did not help.
Other observations (that might or might not be connected):
- The script is located in a folder under Dropbox
- The file has special attributes (that is an "#" appears at the end of the permissions, upon typing ls -lah)
- I might have hit a combination of Control, Apple and other keys that I should not have ....
Any solution to this would be very much appreciated (and my apologies, if that has been treated before).
Thanks!
I also met with this problem recently.
You need to add minor mode Fill. Press on the Python in the mode line in mouse-3 way and choose Auto Fill.