Proposal for new operators to python that add syntactic sugar for hierarcical data.
Gerard Flanagan
grflanagan at yahoo.co.uk
Thu May 18 04:37:57 EDT 2006
glomde wrote:
> i I would like to extend python so that you could create hiercical
[...]
> # build a tree structure
> root = ET.Element("html")
> *!*root:
> *!*head("head"):
> *!*title("title):
> *=*text = "Page Title"
> *!*body("body"):
> *=*bgcolor = "#ffffff"
> *=*text = "Hello, World!"
>
>
>
> I think that with the added syntax you get better view of the html
> page.
> Repeating things dissapears and you get indentation that corresponds to
> the tree.
> I think it is very pythonic IMHO.
>
> It could be done quite generic. If the variable, object after '*!*'
> must support append
> method and if you use '*=*' it must support __setitem__
>
> Any comments?
I personally dislike the nested-indented-brackets type of code given in
other replies, and i think your suggestion has a certain appeal - 'What
you see is what you mean' . But it's not Python.
You also repeat yourself: head("head"), title("title"), body("body")
What about this:
# build a tree structure
root = ET.Element("html")
!root
!head
!title
if A is True:
&text = "Page A"
else:
&text = "Page B"
!body
&bgcolor = "#ffffff"
&text = "Hello, World!"
mmm...yamlthon? yython...:-)
All the best
Gerard
More information about the Python-list
mailing list