[Python-ideas] Unpacking a dict

Nikolaus Rath Nikolaus at rath.org
Tue May 31 12:10:13 EDT 2016

On May 30 2016, Paul Moore <p.f.moore-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> On 30 May 2016 at 16:07, Nikolaus Rath <Nikolaus-BTH8mxji4b0 at public.gmane.org> wrote:
>> Yeah, but that might be useful too :-). How about:
>> extract key foo from d
>> extract attribute foo import d
>> or
>> export key foo from d
>> export attribute foo import d
>> As for "import", with both foo and d required to be identifiers.
> At this point, the question has to be, how is this any better than
> foo = d.foo
> foo = d['foo']

Huh? I thought this has been discussed at length. It's not better in toy
examples, but consider this:

r = query_result
product_id = r['product_id']
quantity = r['quantity']
distributor = r['distributor']
description = r['destription']

Compare to

export key (product_id, quantity, distributor,
            description) from query_result


GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«

More information about the Python-ideas mailing list