Isaac Morland added the comment:

What are the "other issues"?

As to the issue you raise here, that's why I use rename=True.

First create a type with an underscore attribute:

>>> t = namedtuple ('t', ['a', '1234'], rename=True)

(just an easy way of creating such a type; used of namedtuple specifically is 
admittedly a bit of a red herring)

Now create an object and illustrate its attributes:

>>> tt = t ('c', 'd')
>>> tt.a
'c'
>>> tt._1
'd'

Now use my modified attrgetter to get the attributes as a namedtuple:

>>> attrgetter ('a', '_1') (tt)
attrgetter(a='c', _1='d')
>>> 

And the example from the help, used in the test file I've already attached, 
illustrates that the dotted attribute case also works.

Essentially, my patch provides no benefit for attrgetter specified attributes 
that aren't valid namedtuple attribute names, but because of rename=True it 
still works and doesn't break anything.  So if you give "a" as an attribute 
name, the output will have an "a" attribute; if you give "_b" as an attribute 
name, the output will have an "_1" (or whatever number) attribute.  Similarly, 
it doesn't help with dotted attributes, but it doesn't hurt either.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30020>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to