
On Fri, May 27, 2016 at 10:09 AM, Nikolaus Rath <Nikolaus@rath.org> wrote:
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.
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 - solves attribute unpacking Cons: - it's weird - has the potential to be confusing: "from name import other_name" will do different things depending on whether "name" is already bound in current scope - we'd suddenly have 'from ... import ...' statements littered throughout code, rather than nearly always all at the top of the module - dilutes the meaning of "importing" The two pros are nice, but I'm not sure they beat the four cons. FTR, I've not seen anything else in this thread that excites me, but I have only been skimming. -- Zach