[Python-ideas] Unpacking a dict

Brendan Barnwell brenbarn at brenbarn.net
Fri May 27 21:44:17 EDT 2016

On 2016-05-27 11:29, Nikolaus Rath wrote:
> On May 27 2016, Brendan Barnwell <brenbarn-OJtuk2o/0Ank1uMJSBkQmQ at public.gmane.org> wrote:
>> On 2016-05-27 08:09, Nikolaus Rath wrote:
>>> Very true. But as someone else already said (I can't find the email
>>> right now), we have a different construct that everyone is familiar with
>>> and that's easily adapted for this situation:
>>> from dict context import active_id, active_ids, active_model
>>> or more general:
>>> "from dict"  <expr> "import" <identifier list>
>>> Everyone knows that "from .. import .." modifies the local namespace. We
>>> just have to extend it to work not just on modules, but also on
>>> dictionaries.
>> 	One problem with this is that currently "from" doesn't operate
>> on names or objects.  It operates on module paths.  You can't do this:
>> import somepackage as othername
>> from othername import something
>> 	(You'll get "No module named othername".)
>> 	If we change this
> I'm not proposing to change this. I'm proposing to add a new "from dict
> <foo> import <bar>" statement that provides the new functionality.

	Ah, I had missed that.  I agree that resolves the ambiguity, but I 
don't care much for that way of doing it.  Does the object have to be a 
dict?  What about some other mapping type?  If new syntax were to be 
added, it makes more sense to me to change the "verb", a la "from 
someobject get somename".

Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is no 
path, and leave a trail."
    --author unknown

More information about the Python-ideas mailing list