I am using python 2.6 in a virtualenv on an Ubuntu Linux 11.04 (natty) machine. I have this code in my (django) python code:
import pdb ; pdb.set_trace()
in order to launch the python debugger (pdb).
Up until today, this worked fine. But now when the pdb starts, it works for debugging and running and breakpoints etc, but when I press the up arrow to show the previous command it prints ^[[A
instead an doesn't go up. When I type something and press Home, it prints ^[OH
instead of moving the cursor.
I can use up/home/etc. fine in the bash terminal which launches my python django unittests (which has the pdb call).
What's going on? How do I fix my pdb? What's wrong with my readline?
Starting Python Debugger To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().
To start execution, you use the continue or c command. If the program executes successfully, you will be taken back to the (Pdb) prompt where you can restart the execution again. At this point, you can use quit / q or Ctrl+D to exit the debugger.
Once you get you pdb prompt . Just hit n (next) 10 times to exit the loop.
Just use python -m pdb <your_script>. py then b <line_number> to set the breakpoint at chosen line number (no function parentheses). Hit c to continue to your breakpoint. You can see all your breakpoints using b command by itself.
Looks like from some reason you are missing the readline package. Simply install it by typing pip install readline
and it should behave as expected. Remember to type it as superuser if you're not in venv.
I found this problem exists when outputting to both console and file using python file.py 2>&1 | tee output.txt
:
How to redirect stdout to both file and console with scripting?
After removing 2>&1 | tee output.txt
, this problem (up arrow becomes ^[[A
in pdb) disappear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With