[Python-ideas] namedtuple literals [Was: RE a new namedtuple]

Chris Angelico rosuav at gmail.com
Thu Jul 27 19:54:37 EDT 2017

On Fri, Jul 28, 2017 at 9:31 AM, Chris Barker <chris.barker at noaa.gov> wrote:
> On Thu, Jul 27, 2017 at 2:50 PM, Chris Angelico <rosuav at gmail.com> wrote:
>> On Fri, Jul 28, 2017 at 7:22 AM, Pavol Lisy <pavol.lisy at gmail.com> wrote:
>> > maybe:
>> > for x, y, z from spam:
>> >     print(x, y, z)
>> What you're asking for is something like JavaScript's "object
>> destructuring" syntax.
> Wasn't there just a big long discussion about something like that on this
> list?

Yeah, and the use cases just aren't as strong in Python. I think part
of it is because a JS function taking keyword arguments looks like

function fetch(url, options) {
    const {method, body, headers} = options;
    // ...
fetch("http://httpbin.org/post", {method: "POST", body: "blah"});

whereas Python would spell it this way:

def fetch(url, *, method="GET", body=None, headers=[]):

fetch("http://httpbin.org/post", method="POST", body="blah");

So that's one big slab of use-case gone, right there.


More information about the Python-ideas mailing list