Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108640

Re: How to get a directory list sorted by date?

From Michael Selik <michael.selik@gmail.com>
Newsgroups comp.lang.python
Subject Re: How to get a directory list sorted by date?
Date 2016-05-15 15:50 +0000
Message-ID <mailman.33.1463327451.2226.python-list@python.org> (permalink)
References <vmpl0d-l9n.ln1@esprimo.zbmc.eu> <nh9gh6$ekb$1@ger.gmane.org> <20160515061511.7c62b0e1@bigbox.christie.dr> <nha1h2$r6s$1@ger.gmane.org> <CAGgTfkPfL2e419iMLP1012q10x-6dG3vaWDvaTFyPUyMrXh3Kw@mail.gmail.com>

Show all headers | View raw


On Sun, May 15, 2016, 10:37 AM Grant Edwards <grant.b.edwards@gmail.com>
wrote:

> On 2016-05-15, Tim Chase <python.list@tim.thechases.com> wrote:
> > On 2016-05-15 11:46, Peter Otten wrote:
> >> def sorted_dir(folder):
> >>     def getmtime(name):
> >>         path = os.path.join(folder, name)
> >>         return os.path.getmtime(path)
> >>
> >>     return sorted(os.listdir(folder), key=getmtime, reverse=True)
> >>
> >> The same idea will work with pathlib and os.scandir():
> >>
> >> def _getmtime(entry):
> >>     return entry.stat().st_mtime
> >>
> >> def sd_sorted_dir(folder):
> >>     return sorted(os.scandir(folder), key=_getmtime, reverse=True)
> >
> > unless sorted() returns a lazy sorter,
>
> What's a lazy sorter?
>

One that doesn't calculate the next item in the sequence until you ask for
it. It's impossible unless you don't mind an approximation rather than
correct sort.

>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to get a directory list sorted by date? cl@isbd.net - 2016-05-15 09:47 +0100
  Re: How to get a directory list sorted by date? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-15 20:48 +1000
  Re: How to get a directory list sorted by date? Michael Selik <michael.selik@gmail.com> - 2016-05-15 15:50 +0000
  Re: How to get a directory list sorted by date? Grant Edwards <grant.b.edwards@gmail.com> - 2016-05-15 16:00 +0000
  Re: How to get a directory list sorted by date? Tim Chase <python.list@tim.thechases.com> - 2016-05-15 13:12 -0500
    Re: How to get a directory list sorted by date? cl@isbd.net - 2016-05-15 21:23 +0100
  Re: How to get a directory list sorted by date? Chris Angelico <rosuav@gmail.com> - 2016-05-16 07:52 +1000
  Re: How to get a directory list sorted by date? Random832 <random832@fastmail.com> - 2016-05-16 12:40 -0400

csiph-web