Data::Dumper for Python

Dave Benjamin ramen at lackingtalent.com
Thu Oct 28 14:06:12 EDT 2004


In article <opsgkj8cih074qab at news.singnet.com.sg>, 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.

-- 
 .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
        "talking about music is like dancing about architecture."



More information about the Python-list mailing list