Isaac Morland added the comment: Maybe the issue is that I work with SQL constantly. In SQL, if I say "SELECT a, b, c FROM t" and table t has columns a, b, c, d, e, f, I can still select a, b, and c from the result. So to me it is natural that getting a bunch of attributes returns something (row or object, depending on the context), where the attributes are still labelled.
I understand why this was rejected as a universal change to attrgetter - in particular, I didn't re-evaluate the appropriateness of the change once I realized that attrgetter has a C implementation - but I don't understand why this isn't considered a natural option to provide. Using rename=True is just a way of having it not blow up if an attribute name requiring renaming is supplied. I agree that actually using such an attribute requires either guessing the name generated by the rename logic in namedtuple or using numeric indexing. If namedtuple didn't have rename=True then I wouldn't try to re-implement it but since it does I figure it's worth typing ", rename=True" once - it's hardly going to hurt anything. Finally as to use cases, I agree that if the only thing one is doing is sorting it doesn't matter. But with groupby it can be very useful. Say I have an iterator providing objects with fields (heading_id, heading_text, item_id, item_text). I want to display each heading, followed by its items. So, I groupby attrgetter ('heading_id', 'heading_text'), and write a loop something like this: for heading, items in groupby (source, attrgetter ('heading_id', 'heading_text')): # display heading # refer to heading.heading_id and heading.heading_text for item in items: # display item # refer to item.item_id and item.item_text Except I can't, because heading doesn't have attribute names. If I replace attrgetter with namedattrgetter then I'm fine. How would you write this? In the past I've used items[0] but that is (a) ugly and (b) requires "items = list(items)" which is just noise. I feel like depending on what is being done with map and filter you could have a similar situation where you want to refer to the specific fields of the tuple coming back from the function returned by attrgetter. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue31086> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com