object data member dumper?

T

tom arnall

object data member dumper?
George Sakkis george.sakkis at gmail.com
Wed Nov 8 03:42:47 CET 2006
At first I thought pickle would be what you're looking for, because
that's exactly what it does; it dumps arbitrary objects, without
choking on recursive references. Only problem is, it's not human
readable (even in its ascii form).If you want it to be human readable,
you may check the gnosis.xml.pickle module
(http://cheeseshop.python.org/pypi/Gnosis_Utils/1.2.1-a). That's the
output of gnosis.xml.pickle.XML_Pickler(d).dumps() on your example:

<?xml version="1.0"?>
<!DOCTYPE PyObject SYSTEM "PyObjects.dtd">
<PyObject module="__main__" class="D" id="-1210610740">
<attr name="v2" type="numeric" value="2" />
<attr name="o2" type="PyObject" id="-1211043316" module="__main__"
class="B">
<attr name="a" type="PyObject" id="-1211043220" module="__main__"
class="A">
<attr name="p1" type="numeric" value="11" />
</attr>
<attr name="p2" type="numeric" value="12" />
<attr name="v1" type="string" value="3" />
</attr>
<attr name="o1" type="PyObject" id="-1211199412" module="__main__"
class="C">
<attr name="p3" type="numeric" value="5" />
<attr name="b" type="PyObject" id="-1211082644" module="__main__"
class="B">
<attr name="a" type="PyObject" id="-1211067156" module="__main__"
class="A">
<attr name="p1" type="numeric" value="3" />
</attr>
<attr name="p2" type="numeric" value="4" />
<attr name="v1" type="string" value="3" />
</attr>
</attr>
</PyObject>


I've also written a similar but less verbose xml dumper. The gnosis.xml
package provides a bidirectional mapping between objects and xml
(objects -> xml and xml->object) and therefore has to be precise; mine
simply generates a nice xml dump of the object which isn't necessarily
reversible. Here's the output for your example:

<root type="__main__.D">
<o1 type="__main__.C">
<b type="__main__.B">
<a type="__main__.A">
<p1 type="int">3</p1>
</a>
<p2 type="int">4</p2>
<v1 type="str">3</v1>
</b>
<p3 type="int">5</p3>
</o1>
<o2 type="__main__.B">
<a type="__main__.A">
<p1 type="int">11</p1>
</a>
<p2 type="int">12</p2>
<v1 type="str">3</v1>
</o2>
<v2 type="int">2</v2>
</root>


If you find it suits you better, I'll try to make it available
somewhere (probably in the cookbook).

George


George,

did you ever put up your object dumper on the net?

tom arnall
north spit, ca
usa

Make cyberspace pretty: stamp out curly brackets and semicolons.
 
T

tom arnall

George said:
Here it is: http://rafb.net/paste/results/C0NHBp27.html
Mostly undocumented but works for most common types. Most methods are
overridable so you can customize the dumping for a specific type (or
types) in a subclass.


Superb! Thanks very much.

tom arnall
north spit, ca
usa



Make cyberspace pretty: stamp out curly brackets and semicolons.

Loosen up: the tests extend the compiler.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top