[Python-ideas] Method chaining notation

Ron Adam ron3200 at gmail.com
Tue Feb 25 20:43:58 CET 2014



On 02/25/2014 02:21 AM, Stephen J. Turnbull wrote:
> Ron Adam writes:
>
>   > You would probably see it used more often like this...
>   >
>   >     def names(defaults, pos_names, pos_args, kwds):
>   >         return  {}.=update(defaults) \
>   >                   .=update(zip(pos_names, pos_args) \
>   >                   .=update(kwds)
>
> I actually have a bunch of code in one of my apps that implements the
> same thing for a different reason (cascading configs), but my
> implementation is
>
>      def names(defaults, pos_names, pos_args, kwds):
>          for dct in pos_names, pos_args, kwds:
>              defaults.update(dct)
>          return defaults

Not quite the same but close.  I just tried to come up with a more 
realistic example without having to look up a lot code.  How does pos_args 
in your example get paired with names?

Cheers,
    Ron

> The other obvious use for this (as several have posted) is
> accumulating a sequence.  In which case most uses will be well-handled
> with a genexp, or if you need a concrete sequence, a listcomp, and the
> body becomes a one (logical) liner (although it will very likely be
> formatted in multiple lines).



More information about the Python-ideas mailing list