Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'parameters': 0.04; 'skip:[ 20': 0.04; 'argument': 0.05; 'subject:would': 0.07; 'shame': 0.09; 'cc:addr:python-list': 0.11; "wouldn't": 0.14; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "module's": 0.16; 'optional': 0.16; 'sort()': 0.16; 'sorted()': 0.16; 'wrote:': 0.18; 'library': 0.18; 'bit': 0.19; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'directory.': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'message-id:@mail.gmail.com': 0.30; '(which': 0.31; 'code': 0.31; 'directory,': 0.31; 'url:python': 0.33; 'call.': 0.33; 'fri,': 0.33; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'method': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'skip:o 20': 0.38; 'jason': 0.38; 'url:library': 0.38; 'list,': 0.38; 'pm,': 0.38; 'does': 0.39; 'bad': 0.39; 'how': 0.40; 'simply': 0.61; "you're": 0.61; "you'll": 0.62; 'making': 0.63; 'name': 0.63; 'more': 0.64; '20,': 0.68; 'reverse': 0.68; '2015': 0.84; 'good!': 0.84; 'subject:you': 0.87; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=l+BqPconFQWaQ7SXjKIWMMEoJoKWp50XtdEpdtuityg=; b=1CXYAah3dhK+bzMPvdMx5a7Jt1lcPYpGawiEUFYRpzN6BRua2Gy8UjC1+lqKQZiLUP OG5IwCT0xffzqjq3PVNiGBLPQacVHZCBE57pf1WTsknfrBfcrvRqE1Lq0eFDqCv1il4L aS9cz4F/E3emc5/4YFfP5fu6pGweb+vlQn08TimAvt880b0Owmn1f4kfI9LWkB7FM7FV q7u+3lq/bkSLSGdDwRtA0L3LJmGbH+i+Dz8EEp/XoV0usuCmO7MPa2Sz/AwTiBpt49r+ bihspQq2ZRtHKwiJGGBQfmlVC/nwhz4A1BGj8WTH/567fglh8fHFcWFFs+V/4/n8Kydb X1Nw== MIME-Version: 1.0 X-Received: by 10.42.13.193 with SMTP id e1mr9961472ica.59.1424409632677; Thu, 19 Feb 2015 21:20:32 -0800 (PST) In-Reply-To: References: Date: Fri, 20 Feb 2015 16:20:32 +1100 Subject: Re: What behavior would you expect? From: Chris Angelico Cc: python-list Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424409635 news.xs4all.nl 2978 [2001:888:2000:d::a6]:44409 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85946 On Fri, Feb 20, 2015 at 4:13 PM, Jason Friedman wrote: > os.chdir(a_path) > return_list = [os.path.join(a_path, x) for x in glob.glob(a_glob) if > os.path.isfile(x)] > os.chdir(previous_dir) > return reversed(sorted(return_list, key=os.path.getmtime)) > > It's a shame that glob.glob does not take an arbitrary directory as an > optional argument if one does not want to scan the current directory. If you look at the glob module's docs, you'll see how it's implemented: https://docs.python.org/2/library/glob.html You may want to use fnmatch, or possibly just prepend a path name onto your glob. That way, you wouldn't need to change directory, which is almost always a bad idea for a library function. Instead of the reversed() call, you can simply add reverse=True to the sorted() call. And since you're not making use of the original list, you could use its sort() method (which has key and reverse parameters too) to sort a bit more efficiently. But I think your code is pretty good! ChrisA