Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86125 > unrolled thread
| Started by | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| First post | 2015-02-22 08:17 -0600 |
| Last post | 2015-02-22 08:17 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: What behavior would you expect? Tim Chase <python.list@tim.thechases.com> - 2015-02-22 08:17 -0600
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2015-02-22 08:17 -0600 |
| Subject | Re: What behavior would you expect? |
| Message-ID | <mailman.19017.1424615164.18130.python-list@python.org> |
On 2015-02-19 22:55, Jason Friedman wrote:
> > If you're going to call listdir, you probably want to use fnmatch
> > directly.
> >
> > fnmatch seems to be silent on non-existent directories:
> python -c 'import fnmatch; fnmatch.fnmatch("/no/such/path", "*")'
a better test would be glob.glob as fnmatch simply asks "does this
string match this pattern?" so it cares nothing for filenames.
However, it still holds that glob.glob("/does/not/exist/*.txt")
doesn't raise an error but rather just returns an empty list of
iterables.
However, for the OP's question, it's max() that raises an error:
import glob
import os
def most_recent_file(loc, pattern):
globstr = os.path.join(loc, pattern)
return max(glob.glob(globstr), key=lambda f: os.stat(f).st_mtime)
gives me this when the glob returns an empty iterable:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: max() arg is an empty sequence
-tkc
Back to top | Article view | comp.lang.python
csiph-web