Data::Dumper for Python

Jeremy Bowers jerf at jerf.org
Thu Oct 28 14:50:12 EDT 2004


On Thu, 28 Oct 2004 18:06:12 +0000, Dave Benjamin wrote:

> 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:

However, Python tries ***much*** less hard to make those representations
actually evaluate back to equivalent objects. Based on my experiences but
with no particular knowledge of the history of the two languages in this
regard, this is because Python makes many manipulations easy that are hard
to borderline impossible in Perl, and it is much harder to create such
representations in general.

As a result, repr of any but the most base classes is often used more
for "debugging style" info, and str for a simple identification. It is not
safe in general to eval(repr(obj)) and expect anything but a Syntax Error.

Python shuffles that task off to the Pickle module, which is what you'd
want to look up in the docs. That splits human representation off from
computer-reproducable representation, and I believe overall this is
superior; the two are not the same. In addition, we then get the Pickle
protocol extensions which are frequently quite handy, especially when
dealing with weakrefs.



More information about the Python-list mailing list