[Python-ideas] Allow using ** twice

Haoyi Li haoyi.sg at gmail.com
Thu Jun 6 17:43:18 CEST 2013


> There should be one way to do it...

I'd agree except, well, there are two different things that people want to
do here! So in the end you're gonna have to let people do both, somehow.

I'd argue that providing two operators cuts down the number of ways people
do these two things down to two ways, while not providing any operators
leaves people to perform these tasks in a dozen different ways (see the SO
thread I linked). Two ways for two things isn't too bad, when the status
quo is a dozen ways of doing the same two things.

-Haoy


On Thu, Jun 6, 2013 at 11:35 AM, Markus Unterwaditzer <
markus at unterwaditzer.net> wrote:

> A + B would then be the same as B | A, but:
>
> There should be one way to do it...
>
> -- Markus (from phone)
>
> Haoyi Li <haoyi.sg at gmail.com> wrote:
> >> I read `dict1 | dict2` as a mapping that would try dict1 *or* dict2
> >if
> >the key is not in dict1.
> >
> >Idea:
> >
> >dict1 + dict2 -> dict2 takes priority
> >dict1 | dict2 -> dict1 takes priority
> >
> >Does that make sense to anyone? Both + and | are currently un-used
> >iirc.
> >
> >
> >On Thu, Jun 6, 2013 at 11:11 AM, Oscar Benjamin
> ><oscar.j.benjamin at gmail.com>wrote:
> >
> >> On 6 June 2013 16:08, Zachary Ware <zachary.ware+pyideas at gmail.com>
> >wrote:
> >> >> However you can make a class that will try several mappings
> >> sequentially e.g.:
> >> >
> >> > That sounds rather like collections.ChainMap.
> >>
> >> So it does. Thanks for pointing this out; I wasn't aware of it. So as
> >> of PYthon 3.3 you can do:
> >>
> >> from collections import ChainMap
> >>
> >> func(**ChainMap(dict1, dict2))
> >>
> >> Although this does not have the behaviour suggested by the OP (an
> >> error when a key is duplicated).
> >>
> >>
> >> Oscar
> >> _______________________________________________
> >> Python-ideas mailing list
> >> Python-ideas at python.org
> >> http://mail.python.org/mailman/listinfo/python-ideas
> >>
> >
> >
> >------------------------------------------------------------------------
> >
> >_______________________________________________
> >Python-ideas mailing list
> >Python-ideas at python.org
> >http://mail.python.org/mailman/listinfo/python-ideas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130606/b3ae1595/attachment.html>


More information about the Python-ideas mailing list