Is there a Python module that can be used in the same way as Perl\'s Data::Dumper module?
Edit: Sorry, I should have been clearer. I was mainly afte
I too have been using Data::Dumper for quite some time and have gotten used to its way of displaying nicely formatted complex data structures. pprint as mentioned above does a pretty decent job, but I didn't quite like its formatting style. That plus pprint doesn't allow you to inspect objects like Data::Dumper does:
Searched on the net and came across these:
https://gist.github.com/1071857#file_dumper.pyamazon
>>> y = { 1: [1,2,3], 2: [{'a':1},{'b':2}]}
>>> pp = pprint.PrettyPrinter(indent = 4)
>>> pp.pprint(y)
{ 1: [1, 2, 3], 2: [{ 'a': 1}, { 'b': 2}]}
>>> print(Dumper.dump(y)) # Dumper is the python module in the above link
{
1: [
1
2
3
]
2: [
{
'a': 1
}
{
'b': 2
}
]
}
>>> print(Dumper.dump(pp))
instance::pprint.PrettyPrinter
__dict__ :: {
'_depth': None
'_stream': file:: >
'_width': 80
'_indent_per_level': 4
}
Also worth checking is http://salmon-protocol.googlecode.com/svn-history/r24/trunk/salmon-playground/dumper.py It has its own style and seems useful too.