Data::Dumper for Python

Gisle Aas gisle at
Fri Oct 29 09:09:37 CEST 2004

Dave Benjamin <ramen at> writes:

> In article <opsgkj8cih074qab at>, Edward wijaya wrote:
> > Is there any equivalent of it
> > in Python?
> Take a look at the "pprint" module. Also, it's worth noting that the Python
> interpreter prints representations of data structures all the time, no
> library required:
> >>> x = [{'a': a, 'b': b} for a in range(2) for b in range(3)]
> >>> x
> [{'a': 0, 'b': 0}, {'a': 0, 'b': 1}, {'a': 0, 'b': 2}, {'a': 1, 'b': 0},
> {'a': 1, 'b': 1}, {'a': 1, 'b': 2}]
> Read up on the __repr__ and __str__ methods to understand how this mechanism
> works and how to extend it to your own objects.

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).

More information about the Python-list mailing list