On Sat, May 12, 2012 at 6:04 AM, Nick Coghlan <ncogh...@gmail.com> wrote: > On Sat, May 12, 2012 at 12:40 PM, Eric Snow <ericsnowcurren...@gmail.com> > wrote: >> If anyone has strong feelings for item-access over attribute-access, >> please elaborate. I'm just not seeing it as that important and would >> rather finish up the PEP as simply as possible. > > I object to adding a new type to the stdlib just for this PEP.
And I agree with you. :) The only constraint is that it be an object with attribute access. That could be a named tuple, a module, an uninstantiated class, or whatever. A new type is not needed. If it's iterable or not is irrelevant with regards to the PEP. For the implementation I'd like it to have a good repr too, but even that's not part of the proposal. I've got the latest version of the PEP up now. It pares down the type discussion and eliminates "metadata". I figure it's good enough for what we need, and I've put adequate(?) warning that people shouldn't mess with it (consenting adults, etc.). Let me know what you think. > Since > iterating over the keys is significantly more useful than iterating > over the values, that suggests a dictionary as the most appropriate > type. > > If someone *really* wants a quick way to get dotted access to the > contents of dictionary: > >>>> data = dict(a=1, b=2, c=3) >>>> ns = type('', (), data) >>>> ns.a > 1 >>>> ns.b > 2 >>>> ns.c > 3 That's pretty cool. As a counter example, given a normal (dict-based) object you can use vars() to turn it into a dict: >>> data = SomeClass(a=1, b=2, c=3) >>> ns = vars(data) >>> ns['a'] 1 >>> ns['b'] 2 >>> ns['c'] 3 I'll grant that it doesn't work for some objects (like named tuples), but for sys.implementation I don't think it matters either way. -eric _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com