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


Groups > comp.lang.python > #85906

Re: What behavior would you expect?

Return-Path <rosuav@gmail.com>
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 <mc4r7v$cm7$2@dont-email.me>
References <mailman.18856.1424321059.18130.python-list@python.org> <mc4r7v$cm7$2@dont-email.me>
Date Fri, 20 Feb 2015 02:08:49 +1100
Subject Re: What behavior would you expect?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <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.18884.1424358984.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Fri, Feb 20, 2015 at 1:16 AM, Denis McMahon <denismfmcmahon@gmail.com> 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

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


Thread

What behavior would you expect? Jason Friedman <jsf80238@gmail.com> - 2015-02-18 21:44 -0700
  Re: What behavior would you expect? Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-19 14:16 +0000
    Re: What behavior would you expect? Chris Angelico <rosuav@gmail.com> - 2015-02-20 02:08 +1100
      Re: What behavior would you expect? Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-19 20:03 +0000
        Re: What behavior would you expect? Chris Angelico <rosuav@gmail.com> - 2015-02-20 07:11 +1100
          Re: What behavior would you expect? Dan Sommers <dan@tombstonezero.net> - 2015-02-20 04:54 +0000
            Re: What behavior would you expect? Chris Angelico <rosuav@gmail.com> - 2015-02-20 16:16 +1100
              Re: What behavior would you expect? Dan Sommers <dan@tombstonezero.net> - 2015-02-20 05:40 +0000
                Re: What behavior would you expect? Jason Friedman <jsf80238@gmail.com> - 2015-02-19 22:49 -0700
                Re: What behavior would you expect? Paul Rubin <no.email@nospam.invalid> - 2015-02-19 22:18 -0800
                Re: What behavior would you expect? Chris Angelico <rosuav@gmail.com> - 2015-02-20 17:21 +1100
                Re: What behavior would you expect? Paul Rubin <no.email@nospam.invalid> - 2015-02-19 23:18 -0800

csiph-web