On 14Apr2020 21:25, Guido van Rossum <guido@python.org> wrote:
On Tue, Apr 14, 2020 at 9:08 PM Raymond Hettinger < raymond.hettinger@gmail.com> wrote:
[GvR]
We should not try to import JavaScript's object model into Python.
Yes, I get that. Just want to point-out that working with heavily nested dictionaries (typical for JSON) is no fun with square brackets and quotation marks.
Yeah, I get that too. So maybe this should be limited to JSON? Could the stdlib json library be made to return objects that support this (maybe with an option)?
I find this feels slightly special purpose. Though admirably restrained. I think I dislike the need to detour thorough the json module to get such a feature. Like many others, I recently implemented one of these __getattr__+__getitem__ SimpleNamespaces. I'm hacking on some mappings which map dotted-names to values. So the natural implementation is dicts or dict subclasses. But I'm also feeding these to format strings, so I want to write: "Hi {dotted.name}" so I've made a nesting of SimpleNamespace so that I can use nice dotted a.b.c.d type names in the format string. And because I'm using .format_map, the top level namespace also supports __getitem__. Now, my dict subclass has a .ns() method returning one of the above SimpleNamespace subclasses, but I can readily imagine a utility function in collection that made such a thing. Restricting that to only work via some contrived path through the JSON module seems... clunky. Cheers, Cameron Simpson <cs@cskk.id.au>