[New-bugs-announce] [issue16457] Allow operator 'getter' methods to take a list and return a tuple
R. David Murray
report at bugs.python.org
Mon Nov 12 01:17:39 CET 2012
New submission from R. David Murray:
Consider this code snippet, simplified from a real application:
def display(self, *columns)
getter = attrgetter(*columns)
toprint = [[str(x) for x in getter(row)] for row in self._rows]
This works great...as long as there are two or more columns to print.
If there is only one column, it bombs because the getter returns a value
instead of a tuple.
This would not be a problem in and of itself, but there is no way to
tell attrgetter that I want a tuple even if there is only one value.
I believe it would be backward compatible to allow:
attrgetter(['a'])
itemgetter(['a', 'b'])
to return a tuple, since a list cannot be an attribute name. The same
would apply to itemgetter, since a list cannot be a dictionary key.
----------
components: Library (Lib)
messages: 175412
nosy: r.david.murray
priority: normal
severity: normal
stage: needs patch
status: open
title: Allow operator 'getter' methods to take a list and return a tuple
type: enhancement
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16457>
_______________________________________
More information about the New-bugs-announce
mailing list