Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread Miki
I've found myself stumped when trying to organize this list of objects.  The objects in question are timesheets which i'd like to sort by four attributes: class TimeSheet:   department = string   engagement = string   date = datetime.date   stare_hour = datetime.time My ultimate goal

Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread bearophileHUGS
Robocop: then within each department block of the list, have it organized by projects. I don't know what does it means. timesheets.sort(key=operator.attrgetter('string')) Try something like: timesheets.sort(key=attrgetter(department, engagement, date, stare_hour)) My brain might explode if

Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread Robocop
On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote: Robocop: then within each department block of the list, have it organized by projects. I don't know what does it means. timesheets.sort(key=operator.attrgetter('string')) Try something like: timesheets.sort(key=attrgetter(department,

Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread Robocop
On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote: Robocop: then within each department block of the list, have it organized by projects. I don't know what does it means. timesheets.sort(key=operator.attrgetter('string')) Try something like: timesheets.sort(key=attrgetter(department,

Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread Robocop
On Feb 6, 2:17 pm, Robocop btha...@physics.ucsd.edu wrote: On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote: Robocop: then within each department block of the list, have it organized by projects. I don't know what does it means.

Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread Robocop
On Feb 6, 2:20 pm, Robocop btha...@physics.ucsd.edu wrote: On Feb 6, 2:17 pm, Robocop btha...@physics.ucsd.edu wrote: On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote: Robocop: then within each department block of the list, have it organized by projects. I don't know what

Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread Terry Reedy
Robocop wrote: UH OH GUYS! line 110, in sorter timesheets.sort(key=attrgetter(department, engagement, date,start)) 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

Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread Robocop
On Feb 6, 2:34 pm, Robocop btha...@physics.ucsd.edu wrote: On Feb 6, 2:20 pm, Robocop btha...@physics.ucsd.edu wrote: On Feb 6, 2:17 pm, Robocop btha...@physics.ucsd.edu wrote: On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote: Robocop: then within each department block of the

Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread Stephen Hansen
I think there may have been a misunderstanding. I was already using attrgetter, my problem is that it doesn't appear to be sorting by the argument i give it. How does sort work with strings? How about with datetime.time or datetime.date? You were using the attrgetter, but it looks like you

Re: Trouble sorting a list of objects by attributes

2009-02-06 Thread Robocop
On Feb 6, 2:41 pm, Stephen Hansen apt.shan...@gmail.com wrote: I think there may have been a misunderstanding.  I was already using attrgetter, my problem is that it doesn't appear to be sorting by the argument i give it.  How does sort work with strings?  How about with datetime.time or