[Python-ideas] Fwd: About calling syntax

Zaur Shibzoukhov szport at gmail.com
Thu Sep 11 09:53:55 CEST 2008


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

Best regards.
Zaur

2008/9/10 Blake Winton <bwinton at latte.ca>:
> Zaur Shibzoukhov wrote:
>>
>> 2008/9/10 Bruce Leban <bruce at leapyear.org <mailto:bruce at leapyear.org>>
>>
>>    I'm sure there are scenarios where this is useful but I think in
>>    general it would be less readable. As it is, I can't miss a
>>    positional argument in the middle of a long list of keyword arguments:
>>
>>    foo(a=b,c=d,e=f,g=h,i=j,k=l,m)
>>
>>
>> But programmer could select most readable form of function call (as the
>> case may be).
>
> But some of them wouldn't, and I would have to learn all the forms of
> function call to read other people's code.  Additional forms are easy for
> the writer, but hard for the reader, and I read far more code than I write.
>
> To say it a different way, programmers _could_ write easy-to-understand
> Perl, but they can also write hard-to-understand Perl, and in my experience
> when presented with that choice, most of them choose the hard-to-understand
> route.  ;)
>
> Later,
> Blake.
>



More information about the Python-ideas mailing list