[issue5131] pprint doesn't know how to print a defaultdict

Nick Craig-Wood report at bugs.python.org
Wed Sep 29 12:32:16 CEST 2010


Nick Craig-Wood <nick at craig-wood.com> added the comment:

Raymond Hettinger (rhettinger) wrote:
> Ben, I don't think there is any value is opening more issues like pprint-doesn't-handle-object-x (named tuples, defautdicts, deques, generators, etc).
> 
> As it is currently designed, pprint doesn't offer usable hooks and it is not easy to build-out to handle new object types.  For the most part, users just cast to a list before calling pprint.

I mildly disagree, IMHO pprint should be able to make a decent job of all the built in types otherwise it loses its value as a debugging tool.  It is a suprise when a built in type doesn't pprint properly.

This would surely be an excellent use of the abstract base classes defined in the collections module for pprint to make a best guess as to how to print types it doesn't understand directly?

> ISTM, the RightAnswer(tm) is to overhaul pprint and add hooks for handling new objects.  Ideally, there would be flexible print options and reprlib-like features for limiting output and for marking recursive constructs with "..."

That is a very good idea, but might be unecessary with the ABC idea above

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5131>
_______________________________________


More information about the Python-bugs-list mailing list