473,725 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2404


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*******@nets cape.netNOTthis BIT> 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.pick le in Gnosis Utilities.

Some comparisons:
import gnosis.xml.pick le
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.pick le.dumps(o) <?xml version="1.0"?>
<!DOCTYPE PyObject SYSTEM "PyObjects.dtd" >
<PyObject module="__main_ _" class="Somethin g" 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.399999 9999999999" />
<val type="numeric" value="5.599999 9999999996" />
</entry>
<entry>
<key type="numeric" value="7.799999 9999999998" />
<val type="numeric" value="9." />
</entry>
</attr>
<attr name="str" type="string" value="Spam and eggs" />
</PyObject> print yaml.dump(o) --- !!__main__.Some thing
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(ob ject): ... 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__.NewSo mething object at 0x2abbcc>

Gnosis does fine here:
print gnosis.xml.pick le.dumps(o2) <?xml version="1.0"?>
<!DOCTYPE PyObject SYSTEM "PyObjects.dtd" >
<PyObject module="__main_ _" class="NewSomet hing" 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.399999 9999999999" />
<val type="numeric" value="5.599999 9999999996" />
</entry>
<entry>
<key type="numeric" value="7.799999 9999999998" />
<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__.List andTuple
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.pick le 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...idea s have nothing to lose but their chains. Unite
| against "intellectu al 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
1460
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 preserves handles (ie for lambda expressions, dictionaries, lists, etc). Using the pickle module, I can more-or-less accomplish the latter, but not the former. YAML can accomplish the former to some degree, but still can't represent handles. I...
7
2413
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 programmer's perspective, I always hear this term. But when do we need to use hex dump? what's the importances of hex dump? please advise. thanks!!
9
3266
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 Tools to do a memory dump of the app when the lock up occurs, however the stack information is not very useful. I have just put a new build of our system onto production, and this build is a "Debug" build as opposed to a "Release" build. I am...
8
7074
by: suresh_C# | last post by:
Dear All, What is difference between Portable Executable (PE) file and a Assembly? Thanks, Mahesh
6
11308
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, managed by a 3ware controller and using a xfs filesystem. The DB server is a 3 Ghz P4 with 4 Gig of Ram, so the machine is quite fast for most purposes I need it; the DB server is a pure DB server, theres no application running on it. I dump and...
131
6175
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 portable C code - *not only* because, in a 'C sense', I
67
4795
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 or, preferably, more detailed 2) not bounded by Unix timestamp 2038 limit 3) readable in Java 4) writable portably in Perl which seems to mean that 64-bit values are out 5) readable and writable in Python
7
2421
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 seems to work in Firefox and IE 7. In IE 8 and Opera I get one long line, as if the nowrap applied outside the label elements.
4
1933
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 should I use? Thanks a lot.
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9179
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9116
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.