Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I clear the Python pdb screen?

Tags:

python

pdb

Let's say I write

(Pdb) p dir(object)

and, now my screen is taken up with a list of attributes. How can I clear this text while still in debug mode? Importantly, I don't want to lose my place in the code.

like image 207
jds Avatar asked Jun 11 '14 02:06

jds


People also ask

How do I get out of Python pdb?

Whenever you want to leave the pdb console, type the command quit or exit . If you would like to explicitly restart a program at any place within the program, you can do so with the command run .

How do you clear part of a screen in Python?

system('clear') , just write space characters in the lines of the screen that you want to clear. Alternatively, just write the new content, with spaces to pad to the end of the line to clear anything that was there before.

How do you clear a Python debugger?

You can clear the Python interpreter console screen using a system call. System calls to clear the console: For the window system, cls clear the console. For the Linux system, clear command works.

How do I exit pdb and continue?

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.


2 Answers

Depends on your OS. If you're on windows this should work:

import os; os.system('cls')

If you're on GNU/Linux (I think in Mac OS too) this should do the trick:

import os; os.system('clear')

But, if you use bash as you shell interpreter, there is a handy keymap: CTRL+l

like image 120
Magnun Leno Avatar answered Sep 22 '22 00:09

Magnun Leno


You could always print('\n'*30)

like image 29
Peter Gibson Avatar answered Sep 20 '22 00:09

Peter Gibson