Re: Question on sort() key function

2008-01-22 Thread Paul Rubin
Robert Latest <[EMAIL PROTECTED]> writes: > >flist.sort(key=lambda f: f.mod_date.toordinal) > > It doesn't throw an error any more, but neither does it sort the list. This, > however, works: Oh, I didn't realize that toordinal was a callable, given your earlier sample. You want: flist.s

Re: Question on sort() key function

2008-01-22 Thread Marc 'BlackJack' Rintsch
On Tue, 22 Jan 2008 09:56:55 +, Robert Latest wrote: > Peter Otten wrote: >> Robert Latest wrote: >> >> This should work then: >> >> def date_key(f): >> return f.mod_date.toordinal() >> flist.sort(key=date_key) >> >> This can also be written as >> >> flist.sort(key=lambda f: f.mod_date.too

Re: Question on sort() key function

2008-01-22 Thread Robert Latest
Peter Otten wrote: > Robert Latest wrote: > >> Paul Rubin wrote: >>> The attribute is on instances of File, not on the class itself. See >>> if this works: >>> >>>flist.sort(key=lambda f: f.mod_date.toordinal) >> >> It doesn't throw an error any more, but neither does it sort the list. This,

Re: Question on sort() key function

2008-01-22 Thread Peter Otten
Robert Latest wrote: > Paul Rubin wrote: >> The attribute is on instances of File, not on the class itself. See >> if this works: >> >>flist.sort(key=lambda f: f.mod_date.toordinal) > > It doesn't throw an error any more, but neither does it sort the list. This, > however, works: > > -

Re: Question on sort() key function

2008-01-22 Thread Robert Latest
Paul Rubin wrote: > The attribute is on instances of File, not on the class itself. See > if this works: > >flist.sort(key=lambda f: f.mod_date.toordinal) It doesn't throw an error any more, but neither does it sort the list. This, however, works: -- def by_date(f1, f2):

Re: Question on sort() key function

2008-01-22 Thread Paul Rubin
Robert Latest <[EMAIL PROTECTED]> writes: > flist.sort(key=File.mod_date.toordinal) > > However, Python says: > AttributeError: class File has no attribute 'mod_date' The attribute is on instances of File, not on the class itself. See if this works: flist.sort(key=lambda f: f.mod_date.toordi

Question on sort() key function

2008-01-22 Thread Robert Latest
Hello, I have this class: class File: def __init__(self): self.name = '' self.path = '' self.date = 0 self.mod_date = 0 self.keywords = [] self.url = '' ...and after creating a list of File o