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


Groups > comp.lang.python > #61245

Re: One liners

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <torriem+gmail@torriefamily.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'operator': 0.03; 'none:': 0.07; 'above?': 0.16; 'correctness': 0.16; 'fine.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'non- default': 0.16; 'operation,': 0.16; 'quoted': 0.16; 'ternary': 0.16; 'values:': 0.16; 'wrote:': 0.18; 'examples': 0.20; 'preferred': 0.22; 'header:User-Agent:1': 0.23; 'fine': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'code': 0.31; 'stuff': 0.32; 'common': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'should': 0.36; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'short': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'such': 0.63; 'subject:One': 0.74; 'avoids': 0.84; 'functions:': 0.84
X-Virus-Scanned amavisd-new at torriefamily.org
Date Sat, 07 Dec 2013 09:26:42 -0700
From Michael Torrie <torriem@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12
MIME-Version 1.0
To python-list@python.org
Subject Re: One liners
References <CAGGBd_o1TS02cosi+q9YeN5rnWJxe5mU7xtCTuTMZGO0ntF5TA@mail.gmail.com> <52A26763.3070803@gmail.com> <CAGGBd_rsP3rU6X30W_ocF8vNrPrLBrivT+nCv-1htgehmPZWrg@mail.gmail.com> <mailman.3678.1386375653.18130.python-list@python.org> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <roy-10E325.22270006122013@news.panix.com> <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> <qotfvq4suj6.fsf@ruuvi.it.helsinki.fi> <l7vhem$tf1$1@dont-email.me>
In-Reply-To <l7vhem$tf1$1@dont-email.me>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
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.3702.1386433637.18130.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386433637 news.xs4all.nl 2831 [2001:888:2000:d::a6]:41666
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61245

Show key headers only | View raw


On 12/07/2013 09:13 AM, Rotwang wrote:
> On 07/12/2013 12:41, Jussi Piitulainen wrote:
>> [...]
>>
>>    if tracks is None:
>>       tracks = []
> 
> Sorry to go off on a tangent, but in my code I often have stuff like 
> this at the start of functions:
> 
>      tracks = something if tracks is None else tracks
> 
> or, in the case where I don't intend for the function to be passed 
> non-default Falsey values:
> 
>      tracks = tracks or something
> 
> Is there any reason why the two-line version that avoids the ternary 
> operator should be preferred to the above?

I think for such a short operation, and for a common need like this,
what you do is fine.  Personally I prefer the part you quoted from
Jussi, but your examples are just fine for correctness and readability.
 I think Dan's gripes come when cleverness is taken to the extreme.

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


Thread

Re: One liners Michael Torrie <torriem@gmail.com> - 2013-12-06 17:20 -0700
  Re: One liners Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-07 02:28 +0000
    Re: One liners Chris Angelico <rosuav@gmail.com> - 2013-12-07 13:40 +1100
    Re: One liners Roy Smith <roy@panix.com> - 2013-12-06 22:27 -0500
      Re: One liners Chris Angelico <rosuav@gmail.com> - 2013-12-07 15:06 +1100
      Re: One liners Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-07 11:27 +0000
        Re: One liners Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-12-07 14:41 +0200
          Re: One liners Rotwang <sg552@hotmail.co.uk> - 2013-12-07 16:13 +0000
            Re: One liners Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-07 16:25 +0000
              Re: One liners Rotwang <sg552@hotmail.co.uk> - 2013-12-08 02:23 +0000
            Re: One liners Michael Torrie <torriem@gmail.com> - 2013-12-07 09:26 -0700
            Re: One liners Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-12-07 19:49 +0200
            Re: One liners Terry Reedy <tjreedy@udel.edu> - 2013-12-07 16:02 -0500
      Re: One liners Michael Torrie <torriem@gmail.com> - 2013-12-07 09:56 -0700
        Re: One liners rusi <rustompmody@gmail.com> - 2013-12-07 09:10 -0800
      Re: One liners Michael Torrie <torriem@gmail.com> - 2013-12-07 10:02 -0700

csiph-web