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


Groups > comp.lang.python > #85863

Re: What behavior would you expect?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.044
X-Spam-Evidence '*H*': 0.91; '*S*': 0.00; 'none,': 0.07; 'subject:would': 0.07; 'exception,': 0.09; 'exception.': 0.09; 'happen?': 0.09; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function?': 0.16; 'none.': 0.16; 'readable': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'basically': 0.19; 'thu,': 0.19; 'seems': 0.21; 'feb': 0.22; 'cc:addr:python.org': 0.22; '"you': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'wondering': 0.29; 'raise': 0.29; "doesn't": 0.30; 'matching': 0.30; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; 'asked': 0.31; 'getting': 0.31; 'file': 0.32; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'subject:?': 0.36; 'should': 0.36; 'jason': 0.38; 'files': 0.38; 'pm,': 0.38; 'recent': 0.39; 'does': 0.39; 'either': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'is.': 0.60; 'most': 0.60; 'matter': 0.61; 'simply': 0.61; 'name': 0.63; 'such': 0.63; 'situation': 0.65; 'unusual': 0.74; '2015': 0.84; 'timestamps,': 0.84; 'subject:you': 0.87; 'to:none': 0.92; 'remember,': 0.93; 'instant': 0.97
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=FooTVomHLMvQMmyk/KG7BdDZAqW+c0LDqOCv0tL3qGs=; b=xBFq2d+9GGl98L0+LOTtbHKNzzH6yMEC6A2yOchTfjqnYYtUbt3lemTqCJ/PdMz9DK KVanZz+Brx4VUoe2R4Ci0+oBTS5thpHKqZ+0PTSHOJPHR9+l9KEjpG8seUGXW5CRB4bY hwqPrx/CKWrLz1UrkTEQaStte3Dhfql9Qav59NOAPVIYAecmelXjmvUyS2/bOV7rlyy2 A6l08mxGxPyDMxCE4Rvr2tjTY6eHoKwRggq9qkCbbzPO2KHIRHEhMoRXdeQVl2mYLOap DpHRj+umjKnZmakPWatByfraP0DzQ4Cvw6PsVXaLXq5GzeOXxLY24qXuRHU1u3R9M5lU 2kig==
MIME-Version 1.0
X-Received by 10.50.114.4 with SMTP id jc4mr7563630igb.14.1424322602537; Wed, 18 Feb 2015 21:10:02 -0800 (PST)
In-Reply-To <CANy1k1g+wU6VUifZpV5+DWendT2LqS-PhRA-KC5hmq2xQ_uy+A@mail.gmail.com>
References <CANy1k1g+wU6VUifZpV5+DWendT2LqS-PhRA-KC5hmq2xQ_uy+A@mail.gmail.com>
Date Thu, 19 Feb 2015 16:10:02 +1100
Subject Re: What behavior would you expect?
From Chris Angelico <rosuav@gmail.com>
Cc python-list <python-list@python.org>
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 <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.18860.1424322611.18130.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424322611 news.xs4all.nl 2949 [2001:888:2000:d::a6]:51330
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:85863

Show key headers only | View raw


On Thu, Feb 19, 2015 at 3:44 PM, Jason Friedman <jsf80238@gmail.com> wrote:
> I have need to search a directory and return the name of the most recent
> file matching a given pattern.  Given a directory with these files and
> timestamps,
>
> q.pattern1.abc Feb 13
> r.pattern1.cdf  Feb 12
> s.pattern1.efg  Feb 10
> t.pattern2.abc Feb 13
> u.pattern2.xyz  Feb 14
> v.pattern2.efg  Feb 10
>
> calling my_function("/path/to/dir", "pattern1") will return q.pattern1.abc
> and calling my_function("/path/to/dir", "pattern2") will return
> u.pattern2.xyz.

That seems reasonable, and well-defined.

> My question is, what would be a reasonable behavior/result/return value if:
> 1. "/path/to/dir" does not exist or is not readable

Raise an exception. Or, better still, just allow the exception to bubble.

> 2. no files match the given pattern

Either return None, or raise an exception, depending on how "normal"
this state is. Is it simply a matter of "you asked for something, but
you got nothing"? Then return None. Is it a really unusual situation
that should basically never happen? Then raise an exception, so you
get an instant report with no wondering "why am I getting these
strange TypeErrors".

> Also, what would be a reasonable name for such a function?

newest_file_matching() seems decent. Remember, it doesn't have to be
especially short.

ChrisA

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


Thread

Re: What behavior would you expect? Chris Angelico <rosuav@gmail.com> - 2015-02-19 16:10 +1100

csiph-web