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


Groups > comp.lang.python > #86125

Re: What behavior would you expect?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'error:': 0.07; 'subject:would': 0.07; 'string': 0.09; 'raises': 0.09; 'valueerror:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '"does': 0.16; '-tkc': 0.16; 'arg': 0.16; 'cares': 0.16; 'filenames.': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'iterable:': 0.16; 'wrote:': 0.18; 'skip:f 30': 0.19; 'seems': 0.21; 'import': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'cc:2**0': 0.24; 'holds': 0.26; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; "doesn't": 0.30; 'skip:g 30': 0.30; 'gives': 0.31; '"",': 0.31; 'asks': 0.31; 'file': 0.32; 'probably': 0.32; '(most': 0.33; 'test': 0.35; 'but': 0.35; 'sequence': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'list': 0.37; 'received:10': 0.37; 'skip:o 20': 0.38; 'jason': 0.38; 'question,': 0.38; 'rather': 0.38; 'recent': 0.39; 'simply': 0.61; "you're": 0.61; 'to:addr:gmail.com': 0.65; 'directories:': 0.84; 'subject:you': 0.87; 'directly.': 0.95; 'silent': 0.95
X-Sender-Id wwwh|x-authuser|tim@thechases.com
X-Sender-Id wwwh|x-authuser|tim@thechases.com
X-MC-Relay Neutral
X-MailChannels-SenderId wwwh|x-authuser|tim@thechases.com
X-MailChannels-Auth-Id wwwh
X-MC-Loop-Signature 1424614561569:82315289
X-MC-Ingress-Time 1424614561569
Date Sun, 22 Feb 2015 08:17:36 -0600
From Tim Chase <python.list@tim.thechases.com>
To Jason Friedman <jsf80238@gmail.com>
Subject Re: What behavior would you expect?
In-Reply-To <CANy1k1hzJ7gr2n2rGMzTV7i0Dj-sRv5xddoQwtp-svO6BbG0Vg@mail.gmail.com>
References <CANy1k1g+wU6VUifZpV5+DWendT2LqS-PhRA-KC5hmq2xQ_uy+A@mail.gmail.com> <CANy1k1gMgGnqNcgTwjcqfYH-QctZthv89uXcU8SV9Uk6Wji=4A@mail.gmail.com> <CAPTjJmpeYwsQ=XLu5WicVEnqMZpvKJueZRrM9WGafcEm1BFatg@mail.gmail.com> <CANy1k1j8ni7TtZPq_a2r8TUvY13rh0oY8xt-t6+9KPxwfAYEyw@mail.gmail.com> <CAPTjJmpq3t4qb+VD+uL6w+=_wf5v0BFThYFM+a8JAe2RDXpTYg@mail.gmail.com> <CANy1k1hzJ7gr2n2rGMzTV7i0Dj-sRv5xddoQwtp-svO6BbG0Vg@mail.gmail.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AuthUser tim@thechases.com
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.19017.1424615164.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424615164 news.xs4all.nl 2896 [2001:888:2000:d::a6]:38133
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86125

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: What behavior would you expect? Tim Chase <python.list@tim.thechases.com> - 2015-02-22 08:17 -0600

csiph-web