Proposal for new operators to python that add syntactic sugar for hierarcical data.

bruno at modulix onurb at xiludom.gro
Thu May 18 05:13:39 EDT 2006


glomde wrote:
> i I would like to extend python so that you could create hiercical
> tree structures (XML, HTML etc) easier and that resulting code would be
> more readable than how you write today with packages like elementtree
> and xist.
> I dont want to replace the packages but the packages could be used with
> the
> new operators and the resulting IMHO is much more readable.
> 
> The syntax i would like is something like the below:
> 
> # Example creating html tree 
> '*!*' is an operator that creates an new node,
> '*=*' is an operator that sets an attribute.
> 
(snip)
> 
> With syntactical sugar:
> 
>   # build a tree structure
>   root = ET.Element("html")
>   *!*root:
>      *!*head("head"):
>          *!*title("title):
>               *=*text = "Page Title"
>      *!*body("body"):
>               *=*bgcolor = "#ffffff"
>               *=*text = "Hello, World!"
> 

What about using <XXX>data</XXX> for nodes and '=' for attributes ?
Would look like:

<html>
  <head>
    <title>Page Title</title>
  </head>
  <body bgcolor='#ffffff'>
    Hello World
  </body>
</html>

> 
> I think that with the added syntax you get better view of the html
> page.

indeed !-)

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list