473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Portable readable dump format


Is there a human readable dump format for objects ? As opposed to pickling ?
It doesn't necessarily have to be XML - in fact i'd prefer if it wasn't ;) -
but ISTR an XML dump library.

--
regards, chris
Jul 18 '05 #1
3 2385


Chris Stiles wrote:
Is there a human readable dump format for objects ? As opposed to pickling ?
It doesn't necessarily have to be XML - in fact i'd prefer if it wasn't ;) -
but ISTR an XML dump library.


There is YAML http://yaml.org/

and http://python.yaml.org/, http://yaml.freepan.org/index.cgi?LibSyck

Jul 18 '05 #2
Donald 'Paddy' McCarthy <pa*******@netscape.netNOTthisBIT> writes:
There is YAML http://yaml.org/

and http://python.yaml.org/, http://yaml.freepan.org/index.cgi?LibSyck


Thank you. That was exactly the library I was after.

--
regards, chris
Jul 18 '05 #3
Chris Stiles <ch***@example.org> wrote previously:
|Is there a human readable dump format for objects ? As opposed to
|pickling ? It doesn't necessarily have to be XML - in fact i'd prefer
|if it wasn't ;) - but ISTR an XML dump library.

Another poster pointed to YAML, which is a good format. If you want
XML, however, I have gnosis.xml.pickle in Gnosis Utilities.

Some comparisons:
import gnosis.xml.pickle
import yaml
class Something: ... def __init__(self):
... self.tup = (1,2,3)
... self.dct = {1.4:5.6,7.8:9.0}
... self.str = "Spam and eggs"
... o = Something()
print gnosis.xml.pickle.dumps(o) <?xml version="1.0"?>
<!DOCTYPE PyObject SYSTEM "PyObjects.dtd">
<PyObject module="__main__" class="Something" id="2283692">
<attr name="tup" type="tuple" id="2577828" >
<item type="numeric" value="1" />
<item type="numeric" value="2" />
<item type="numeric" value="3" />
</attr>
<attr name="dct" type="dict" id="2829140" >
<entry>
<key type="numeric" value="1.3999999999999999" />
<val type="numeric" value="5.5999999999999996" />
</entry>
<entry>
<key type="numeric" value="7.7999999999999998" />
<val type="numeric" value="9." />
</entry>
</attr>
<attr name="str" type="string" value="Spam and eggs" />
</PyObject> print yaml.dump(o) --- !!__main__.Something
dct:
1.4: 5.6
7.8: 9.0
str: Spam and eggs
tup:
- 1
- 2
- 3

Certainly YAML is a lot less verbose (but also in a way less explicit).
The method 'yaml.dump()' is misnamed, however, it should have an 's' at
the end.

However, notice this:
class NewSomething(object): ... def __init__(self):
... self.tup = (1,2,3)
... self.dct = {1.4:5.6,7.8:9.0}
... self.str = "Spam and eggs"
... o2 = NewSomething()
print yaml.dump(o2) --- <__main__.NewSomething object at 0x2abbcc>

Gnosis does fine here:
print gnosis.xml.pickle.dumps(o2) <?xml version="1.0"?>
<!DOCTYPE PyObject SYSTEM "PyObjects.dtd">
<PyObject module="__main__" class="NewSomething" id="2800588">
<attr name="tup" type="tuple" id="2576628" >
<item type="numeric" value="1" />
<item type="numeric" value="2" />
<item type="numeric" value="3" />
</attr>
<attr name="dct" type="dict" id="2829820" >
<entry>
<key type="numeric" value="1.3999999999999999" />
<val type="numeric" value="5.5999999999999996" />
</entry>
<entry>
<key type="numeric" value="7.7999999999999998" />
<val type="numeric" value="9." />
</entry>
</attr>
<attr name="str" type="string" value="Spam and eggs" />
</PyObject>

Moreover, notice this:
class ListandTuple: ... def __init__(self):
... self.tup = (1,2,3)
... self.lst = [1,2,3]
... lt = ListandTuple()
print yaml.dump(lt)

--- !!__main__.ListandTuple
lst:
- 1
- 2
- 3
tup:
- 1
- 2
- 3

YAML is lossy in regard to Python types. Some other languages supported
by the YAML format do not have the list/tuple distinction, but since
Python does, usually you want to keep it (which gnosis.xml.pickle does).

Yours, David...

--
mertz@ | The specter of free information is haunting the `Net! All the
gnosis | powers of IP- and crypto-tyranny have entered into an unholy
..cx | alliance...ideas have nothing to lose but their chains. Unite
| against "intellectual property" and anti-privacy regimes!
-------------------------------------------------------------------------
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chris S. | last post by:
I'm trying to write programs that make use of a lot of dynamic structures. To aid in debugging and data extraction, I'd like to persist these objects in a form that's readable, but one that also...
7
by: Matt | last post by:
I want to know what is Hex Dump? I tried to search in google but didn't get useful results. I know it is the hexademical representation of something. But I don't know what is something? From C...
9
by: Microsoft News Server | last post by:
Hi, I am currently having a problem with random, intermittent lock ups in my ASP.net application on our production server (99% CPU usage by 3 threads, indefinately). I currently use IIS Debug...
8
by: suresh_C# | last post by:
Dear All, What is difference between Portable Executable (PE) file and a Assembly? Thanks, Mahesh
6
by: Soeren Gerlach | last post by:
Hi, some weeks ago I started to develop an application using Postgresql the first time. I'm running 7.4.3 on a Linux box with a plain 2.6.7 kernel, the storage is handled by 5 SATA disks,...
131
by: pemo | last post by:
Is C really portable? And, apologies, but this is possibly a little OT? In c.l.c we often see 'not portable' comments, but I wonder just how portable C apps really are. I don't write...
67
by: James Harris | last post by:
I have a requirement to store timestamps in a database. Simple enough you might think but finding a suitably general format is not easy. The specifics are 1) subsecond resolution - milliseconds...
7
by: Chris Riesbeck | last post by:
What's the right way to make sure checkboxes stick with their labels when the window is resized? Right now I'm trying <label><input ...text</labelwith white-space:nowrap on label, but this only...
4
by: nielinjie | last post by:
Hi list: I just want to marshal objects (instance of custom classes)to a human *READABEL *file/string, and also, I want unmarshal it back. in xml format or any other format. Any advice? Which lib...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.