473,238 Members | 1,834 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,238 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 2373


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: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

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.