[Python-ideas] Unpacking a dict

Nikolaus Rath Nikolaus at rath.org
Tue May 31 12:11:52 EDT 2016


On May 30 2016, Ethan Furman <ethan-gcWI5d7PMXnvaiG9KC9N7Q at public.gmane.org> wrote:
> On 05/30/2016 08:07 AM, Nikolaus Rath wrote:
>> On May 29 2016, Guido van Rossum <guido-+ZN9ApsXKcEdnm+yROfE0A-XMD5yJDbdMReXY1tMh2IBg at public.gmane.org> wrote:
>>>> using other words still on the table?
>>>>
>>>>   d = {"foo": 42}
>>>>   <something> d <something> 42 # or the other way around
>>>>   assert foo == 42
>>>
>>> This I don't understand -- why would the '42' appear in the extraction
>>> syntax? I guess you meant "foo"?
>>
>> Yes, sorry.
>>
>>> Maybe we can riff on
>>>
>>>    extract foo from d
>>>
>>> ? Though honestly that looks like it would be extracting d.foo, no
>>> d['foo'].
>>
>> 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.
>
> The versions with "import" in them are DAAP (dead-as-a-parrot).  No
> point in even talking about them.

Aeh, yeah. No idea how I ended up writing that. What I meant was

 extract key foo from d
 extract attribute foo from d

 or

 export key foo from d
 export attribute foo from d


i.e, contrast "extract" with "export" for attribute access and dict
access. 


Best,
-Nikolaus

-- 
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