[Python-ideas] Unpacking a dict
Michael Selik
michael.selik at gmail.com
Fri May 27 11:41:41 EDT 2016
On Fri, May 27, 2016 at 11:38 AM Zachary Ware <
zachary.ware+pyideas at gmail.com> wrote:
> On Fri, May 27, 2016 at 10:32 AM, Michael Selik <michael.selik at gmail.com>
> wrote:
> >
> >
> > On Fri, May 27, 2016 at 11:28 AM Zachary Ware
> > <zachary.ware+pyideas at gmail.com> wrote:
> >>
> >> Here's a crazy thought that might be best dismissed out of hand: what
> >> about extending 'from name import other_names' to accept any object
> >> for <name>? First try to get values via __getitem__() (possibly only
> >> for dict/dict subclasses?), next try getattr(), finally try to import
> >> the module and pull values from it as per usual.
> >>
> >> Pros:
> >> - solves dict unpacking
> >
> >
> > Would it solve nested dict unpacking?
>
> How do you mean? Replacing `some_name =
> some_dict['some_key']['some_name']` with `from some_dict['some_key']
> import some_name`?
>
No, more like
py> {'name': name, 'location': {0: row, 1: col} = mapping
py> name, row, col
('Mike', 3, 5)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160527/496b4821/attachment.html>
More information about the Python-ideas
mailing list