[Python-ideas] Unpacking a dict

Chris Angelico rosuav at gmail.com
Thu May 26 23:15:29 EDT 2016

On Fri, May 27, 2016 at 1:05 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 05/26/2016 07:57 PM, Chris Angelico wrote:
>> On Fri, May 27, 2016 at 12:43 PM, Rob Cliffe wrote:
>>> How about
>>>      locals().update(values)
>> Because locals() can't be updated unless it happens to be the same
>> dict as globals(), in which case it's clearer to use that name.
> Actually, the dict returned by locals() can be updated, but at least in
> cPython those updates don't make it back to the function's locals (although
> they do in other Python's).

Sorry, yeah. The dict is a dict, so of course it can be updated, but
the changes aren't guaranteed to have effect. Point is, it's not a
suitable way to do this. :)


More information about the Python-ideas mailing list