Data::Dumper for Python

Josiah Carlson jcarlson at uci.edu
Fri Oct 29 09:34:31 CEST 2004


Gisle Aas <gisle at activestate.com> wrote:
> Data::Dumper will automatically show instance variables of your
> objects and recurse down into their representation.  pprint does not
> do that.  Because of this I find pprint quite useless (at least as a
> replacement for Data::Dumper).

Python's pprint is a fairly simple little module.  A reasonably
experienced Python programmer could probably toss off a clone of it in a
weekend if given a description of it.

With that said, pprint only 'beautifies' lists, tuples and dictionaries. 
If one wants something that does more, the source for pprint is readily
available in any Python distribution, to be customized to print
arbitrary class attributes as you (or someone else) finds necessary.

I would imagine that the reason why such an addition was not already
made is because textual representations of objects are not necessarily
round-tripable via eval(repr(obj)) (which has been mentioned before),
and a pprinted representation of an arbitrary user-class (as would be
presented by an altered pprint) is almost certainly not round-tripable
via eval(pprinted_representation(obj)).

 - Josiah




More information about the Python-list mailing list