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

Alan Kennedy alanmk at hotmail.com
Thu May 18 05:24:28 EDT 2006


[glomde]
> 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.

> Any comments?

Yes: it's ugly and unnecessary.

Why would you want to change the language syntax just to make it easier
to express markup directly in program code? Javascript just made that
mistake with E4X: IMHO, it makes for some of the ugliest code. E4X
reminds me of that Microsoft b*stardisation, XML Data Islands.

http://www.w3schools.com/e4x/e4x_howto.asp
http://en.wikipedia.org/wiki/E4X

For a nice pythonic solution to representing markup directly in python
code, you should check out stan.

http://divmod.org/users/exarkun/nevow-api/public/nevow.stan-module.html

Here's a nice stan example, taken from Kieran Holland's tutorial

http://www.kieranholland.com/code/documentation/nevow-stan/

aDocument = tags.html[
  tags.head[
    tags.title["Hello, world!"]
  ],
  tags.body[
    tags.h1[ "This is a complete XHTML document modeled in Stan." ],
    tags.p[ "This text is inside a paragraph tag." ],
    tags.div(style="color: blue; width: 200px; background-color:
yellow;")
      [
      "And this is a coloured div."
      ]
  ]
]

That looks nice and simple, and no need to destroy the elegance of
python to do it.

regards,

--
alan kennedy
------------------------------------------------------
email alan:              http://xhaus.com/contact/alan




More information about the Python-list mailing list