hotel Hudson
Powered by Best Free Counters

Tuesday, December 28, 2010

PyDON – The Python Dictionary Object Notation @ lostp.99k.org

PyDON – The Python Dictionary Object Notation

Abstract:
---------

I am terribly bored of JSON and XML parsing methodologies in this wonderful language called ‘Python’. So in here, I present to you the Python Dictionary Object Notation. This might make life easier for Python Coders. More documents and updates on this will be published as I continue my research on PyDON.

Introduction:
-------------
So, what _IS_ PyDON? We have all heard of JSON and XML used as dominant format for information exchange. But the problem is, since XML introduces extra overhead of writing the ending tag, and JSON being native to JavaScript, I decided to search for something similar on Python.
After a little AHA moment – I got the idea for PyDON.

Explanation:
------------
Using Python’s inbuilt dictionary data-type and the ‘execfile()’ builtin function it’s easy to implement all the functionalities of XML and JSON(and soon you will see its better than JSON).
Consider the XML below

PyDON
Python Dictionary Object Notation


Parsing this would require programmers to write XML Parser, walk the tree, get the necessary node blah blah all the pain for something so SIMPLE as ‘Information eXchange’ (IX). Instead, what if Python programmers got their own format? Wouldn’t it make the whole IX simpler? That’s what set me up on PyDON. The same XML in PyDON (*.pdn) format will be

Parsing this is easy. Save it as say foo.pdn, then just execfile(“foo.pdn”) and voila. No extra code necessary, no external libraries. NO NOTHING. We can simply access the various parts of “data” like so >
Hello = data[“Language”]
print “Hello “, Hello

Also a complex XML script like the following can also be easily converted to PyDON.

LostP
www.lostp.99k.org
yaj00@yahoo.com
True
000-00-000

funcName



This is a pretty complex XML script. Equivalent PyDON is
data = {
“Address”: {
“Name”:”LostP”,
“Address”:”www.lostp.99k.org”,
“Email”:”yaj00@yahoo.com”,
“IsMale?”:True,
“PhoneNumber”:00000000
} ,
“WhatToDoIfFound”: {
“ExecuteFunction”:funcName
}
};

Doesn’t this look a LOT better than its XML counterpart?
How about parsing it? PIECE OF CAKE.
Save it as foo.pdn again.

> execfile(“foo.pdn”)

And voila(once again) you don’t have to write a parser. Just type in
Address = data[“Address”]
WhatToDoIfFound = data[“WhatToDoIfFound”]
if Address[“Name”] == “LostP”:
if Address[“IsMale?”]:
WhatToDoIfFound[“ExecuteFunction”]()

I see limitless possibilities in where PyDON can be used. We are only limited by our imagination. One example is that it can also be used to store important initialization details for a particular application( ala Windows .INI file ).
If you use this information, please do give me and my website credits. Thanks
-Lost Protocol.

No comments:

Post a Comment