diff options
author | Barry Warsaw <barry@python.org> | 2002-11-05 22:40:20 +0000 |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2002-11-05 22:40:20 +0000 |
commit | 3d3fd182010499e3a6bd1d3fa7fbd4ba7f8467bc (patch) | |
tree | b5afbf905e64e77a73644b9019428d4f5ef4f10b /Lib/pdb.py | |
parent | b59937e6dd7e407d57ae4506e7b736810a7c1889 (diff) | |
download | cpython-3d3fd182010499e3a6bd1d3fa7fbd4ba7f8467bc.tar.gz |
Implement a `pp' command, which is like `p' except that it
pretty-prints the value of its expression argument.
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-x | Lib/pdb.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py index 4b0516d28a..94518aebf6 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -11,6 +11,7 @@ import bdb from repr import Repr import os import re +import pprint # Create a custom safe Repr instance and increase its maxstring. # The default of 30 truncates error messages too easily. @@ -532,19 +533,29 @@ class Pdb(bdb.Bdb, cmd.Cmd): print '*** Not yet returned!' do_rv = do_retval - def do_p(self, arg): + def _getval(self, arg): try: - value = eval(arg, self.curframe.f_globals, - self.curframe.f_locals) + return eval(arg, self.curframe.f_globals, + self.curframe.f_locals) except: t, v = sys.exc_info()[:2] - if type(t) == type(''): + if isinstance(t, str): exc_type_name = t else: exc_type_name = t.__name__ print '***', exc_type_name + ':', `v` - return + raise + + def do_p(self, arg): + try: + print repr(self._getval(arg)) + except: + pass - print `value` + def do_pp(self, arg): + try: + pprint.pprint(self._getval(arg)) + except: + pass def do_list(self, arg): self.lastcmd = 'list' @@ -817,6 +828,10 @@ Print the arguments of the current function.""" print """p expression Print the value of the expression.""" + def help_pp(self): + print """pp expression +Pretty-print the value of the expression.""" + def help_exec(self): print """(!) statement Execute the (one-line) statement in the context of |