[Python-ideas] Python Object Notation (PyON)

Zaur Shibzoukhov szport at gmail.com
Sat Nov 1 20:47:07 CET 2008

Terry Reedy wrote:

> Other than syntax details, how is PyON different from json, yaml (3rd
> party module), and anything else?

I hope that PyON can be seen as native literal object notation for objects
in python language. Similar to what JSON is for JavaScript ;) JavaScript
hasn't classes, but python has that. So we could say that PyON in some way
extends JSON. I that it's better reflecting python's object model.

I'l try to explain this by example. Let

class Person(object):

person = Person()
person.name = 'John'
person.age = 33

First, in PyON person represents as "Person(name='John', age=33)" and loads
return an instance of Person.
In JSON we need to represent person in a way similar to "{'class':'Person',
'name':'John', 'age':33}" and loads always return dict-like structure, not
instance of Person.

Second, object instance reconstruction from PyON string or AST performs
according to picklie protocol (3). This mean that if we define class that
implements right methods in accordance to pickle protocol then we can dumps
to PyON string and loads from that.

I didn't yet made comparison with yaml. I should do that too. Now I can only
say that yaml is much complicated notation (IMHO).

>>> Grammar: <kw> := <name> = <pyon_expr>, ..., <name> = <pyon_expr>
>>> There is no rule for pyon_expr. Did you just mean <expr>?
You right, thank you. This a tipo. I'l update the page.

> ... y=IF(
> ... flag,
> ... A1(kind='A1'),
> ... A2(kind='A2')
> ... )

This didn't covered by current rough gramma definition. I still do not know
if this must be a part of PyON.
The fact is that PyON can be extended to thing such as "object template" and
current implementation include some of such opportunities. One of this you
pointed out here. Here is another example:
       person = loads("Person(name=real_name, age=real_age)",
real_name='John', real_age=33)

Best regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20081101/5d806b9d/attachment.html>

More information about the Python-ideas mailing list