Trouble sorting a list of objects by attributes
tjreedy at udel.edu
Fri Feb 6 17:34:51 EST 2009
> UH OH GUYS!
> line 110, in sorter
> timesheets.sort(key=attrgetter("department", "engagement",
> TypeError: attrgetter expected 1 arguments, got 4
Um... what version of Python are you running? Alway specify. (Too many
people do not). In 3.0
from operator import attrgetter
runs fine as per the doc.
Return a callable object that fetches attr from its operand. If more
than one attribute is requested, returns a tuple of attributes. After, f
= attrgetter('name'), the call f(b) returns b.name. After, f =
attrgetter('name', 'date'), the call f(b) returns (b.name, b.date).
More information about the Python-list