4

I am using ipdb to debug a python script.

I want to print a very long variable. Is there any ipdb pager like more or less used in shells?

Thanks

gc5
  • 9,468
  • 24
  • 90
  • 151
  • Save it to a file in the debug session and examine it with a proper text editor? – YXD May 14 '13 at 11:36
  • What is wrong with just printing it and scrolling up your terminal window? – mawimawi May 14 '13 at 11:57
  • The fact is that the variable can be thousands of lines long, to display it requires thousands of lines in the terminal buffer. Also, I'd prefer to not use a file, to have directly my output in the debugger.. – gc5 May 14 '13 at 12:53

1 Answers1

3

You might want to create a function which accepts a text, puts this text into a temporary file, and calls os.system('less %s' % temporary_file_name).

To make it easier for everyday use: Put the function into a file (e.g: ~/.pythonrc) and specify it in your PYTHONSTARTUP.

Alternatively you can just install bpython (pip install bpython), and start the bpython shell using bpython. This shell has a "pager" functionality which executes less with your last output.

mawimawi
  • 4,222
  • 3
  • 33
  • 52