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


Groups > comp.lang.python > #85954

Re: What behavior would you expect?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'value,': 0.04; 'subject:would': 0.07; 'string': 0.09; '"if': 0.09; 'filename': 0.09; 'type,': 0.09; 'cc:addr:python-list': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'simulate': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'written': 0.21; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'paul': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; 'bad.': 0.31; 'option': 0.32; 'fri,': 0.33; 'could': 0.34; 'something': 0.35; 'case,': 0.35; 'received:google.com': 0.35; 'returning': 0.36; "didn't": 0.36; 'subject:?': 0.36; 'list': 0.37; 'list.': 0.37; 'sometimes': 0.38; 'pm,': 0.38; 'simply': 0.61; '20,': 0.68; '2015': 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=J64RSm24N4HZcpXDGhpzkYryBKdZ5av1IQMKDMGwPpc=; b=AqCgyK+eFYApWczWx2Erngr0qj3Y8vMctiRcAO+UHJzkKXFR2tGDn3tLm4U2FLZ8gm 2hoBuzeevT98bgzIsA2XpLDMnetRifZlyVC0IDLlGVtvMeO7ZoFrJnZ22yRSsPNRn8SS B8WlEsIenmQ8RnodrMJYKLJGoyA1pwKz4DNd4CGqNHyIJUrntkE4DB14qpUTBLDMelWf 23WFW2b159s6iakSuENKJxZWnzfmeK/h3ynOqlDtpgTcibjA1tSuL8IE6afFcGErKRNf iSmHBMkfd99OQxz8WUqH3lNq+hw8JC4zBslsHKhhLGSQXOYHQq41viPs+QHS1XXP+5o4 h34Q==
MIME-Version 1.0
X-Received by 10.42.13.193 with SMTP id e1mr10128272ica.59.1424413311331; Thu, 19 Feb 2015 22:21:51 -0800 (PST)
In-Reply-To <87r3tlds2l.fsf@jester.gateway.pace.com>
References <mailman.18856.1424321059.18130.python-list@python.org> <mc4r7v$cm7$2@dont-email.me> <mailman.18884.1424358984.18130.python-list@python.org> <mc5fiq$a3f$3@dont-email.me> <mailman.18902.1424376675.18130.python-list@python.org> <mc6emp$j1q$1@dont-email.me> <mailman.18908.1424409419.18130.python-list@python.org> <mc6hd4$j1q$2@dont-email.me> <87r3tlds2l.fsf@jester.gateway.pace.com>
Date Fri, 20 Feb 2015 17:21:51 +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.18914.1424413711.18130.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424413711 news.xs4all.nl 2906 [2001:888:2000:d::a6]:38952
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:85954

Show key headers only | View raw


On Fri, Feb 20, 2015 at 5:18 PM, Paul Rubin <no.email@nospam.invalid> wrote:
> Empty string would be bad.  Sometimes I like to simulate an option type,
> by returning the value as a 1-element list if there's a value, otherwise
> as an empty list.  So you could say
>
>   filename = get_filename(...)[0]
>
> if you want an exception in the failure case, or you could do something
> like
>
>   fs = get_filename(...)
>   if len(fs) == 0:  ... # didn't get a filename

Bikeshedding: That could be written as simply "if not fs". :)

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