[Python-ideas] Fwd: About calling syntax

Georg Brandl g.brandl at gmx.net
Thu Sep 11 11:00:03 CEST 2008


Zaur Shibzoukhov schrieb:
> Returning to initial topic of my posts I said about calling function
> in the case:
> 
> class Element(object):
>     def __init__(self, name, *args, **kw):
>       self.__dict__.update(kw)
>       self.chidren.extend(args)
> 
> I tried to find more natural form of initializing such tree-like
> structures in python.
> In current syntax the only available form (which is natural to me) is:
> 
> Element('root',
>    x='1', y='2', *[
>    Element('child1',
>       x='1', y='2', *[
>       Element(''grandchild1', x='4', y='6'),
>       Element(''grandchild2', x='7', y='8')
>    ]),
>    Element(''grandchild1', x='4', y='6')
> ])
> 
> I hoped that python calling syntax could be extended in order to allow
> writing such initializaing code without *[ ... ]

Element('root',
    x='1', y='2', c=[
    Element('child1',
       x='1', y='2', c=[
       Element(''grandchild1', x='4', y='6'),
       Element(''grandchild2', x='7', y='8')
    ]),
    Element(''grandchild1', x='4', y='6')
])

Voila! ;)

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.




More information about the Python-ideas mailing list