Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string.': 0.05; 'matches': 0.07; 'none,': 0.07; 'subject:would': 0.07; 'string': 0.09; 'exception,': 0.09; 'false,': 0.09; 'happen?': 0.09; 'raises': 0.09; 'target,': 0.09; 'api': 0.11; 'cc:addr:python-list': 0.11; 'file"': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'fairly': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'options': 0.25; 'code:': 0.26; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'matching': 0.30; 'moved': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'raised': 0.31; 'trace': 0.31; 'file': 0.32; 'probably': 0.32; 'up.': 0.33; 'fri,': 0.33; "i'd": 0.34; 'could': 0.34; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'next': 0.36; 'subject:?': 0.36; 'should': 0.36; 'two': 0.37; 'handle': 0.38; 'files': 0.38; 'either': 0.39; 'catch': 0.60; 'matter': 0.61; 'back': 0.62; 'different': 0.65; 'between': 0.67; '20,': 0.68; '2015': 0.84; 'prefers': 0.84; 'subject:you': 0.87; 'to:none': 0.92; 'imagine': 0.93 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=Ig8cTE6FfNY9AbblC09dwqBD24aW8N7zZ3WEubrLY+M=; b=d7M9aCATAaFiKloySuPV3cXuNH6lM1WLFzG/FXh+2LzUv93qb8b/sJOlkg5e5R/awi yQfiz9CueJhRc23Lv+2lxV5OFnJ//0W4LqEMo4dsp+XqjftrUbVPm6/VjTY+t5Zc/rde kDDLnIuNaqPenfrBPW3uAv8xLlyAEiY0K3i4mBfhN+UwhwZ8crMxF8EUd8S+eFjf6S4/ wQq7x8TwKTjkMNSU1ZP51jHyJTKYfjI5dev5IDhh4YHirdJ9GMJxIfRbJe5jReUTZos1 vvFFX5a9e5NcZczgICS+7DVoVGUM1nDpM7ljH0Fz1/94ctUtbOMo/S3uf9fnqo1D0oXP YlZw== MIME-Version: 1.0 X-Received: by 10.42.52.200 with SMTP id k8mr6563082icg.26.1424358529795; Thu, 19 Feb 2015 07:08:49 -0800 (PST) In-Reply-To: References: Date: Fri, 20 Feb 2015 02:08:49 +1100 Subject: Re: What behavior would you expect? From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424358984 news.xs4all.nl 2869 [2001:888:2000:d::a6]:40768 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:85906 On Fri, Feb 20, 2015 at 1:16 AM, Denis McMahon wrote: >> 2. no files match the given pattern > > Return either None, 0, False or an empty string. > > In both cases, it is then a matter for the calling code to catch the > exception or handle the return value appropriately. I'd avoid the empty string here, because "absence of file" should be very different from "first file matching pattern". Imagine this naive code: fn = my_function("/path/to/dir", "pattern2") move_to("/path/to/dir/" + fn, "/other/path") In the failure case (nothing matches the pattern), what could happen? Best is it raises an exception, which would come from the my_function line. Next best, it returns None, 0, or False, and you get a TypeError on the deletion, and can trace your way back up. Worst, it returns "" and oops, you just moved the whole directory into the target, instead of just one file. Of course, non-naive code probably prefers a None/0/False return to a raised exception, but in any case, the difference between those two options is fairly small. But I'd avoid the potential confusion with the empty string. Anyway, that's just API bike-shedding :) ChrisA