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


Groups > comp.lang.python > #61385

Re: One liners

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'programmer': 0.03; 'yet.': 0.04; 'think,': 0.07; 'ugly': 0.07; '__init__': 0.09; 'dan': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rewrite': 0.09; 'python': 0.11; 'culturally': 0.16; 'generators.': 0.16; 'get,': 0.16; 'nod.': 0.16; 'pythonic': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'comfortable': 0.22; 'header:User-Agent:1': 0.23; 'fairly': 0.24; "haven't": 0.24; 'nearly': 0.26; 'possibly': 0.26; 'header:X-Complaints-To:1': 0.27; 'generally': 0.29; 'sets': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'perl': 0.31; 'this.': 0.32; 'probably': 0.32; 'comment': 0.34; 'objects': 0.35; 'but': 0.35; 'really': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'turn': 0.37; 'filter': 0.38; 'mine': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'break': 0.61; 'new': 0.61; "you're": 0.61; 'first': 0.61; 'name': 0.63; 'refer': 0.63; 'skip:n 10': 0.64; 'choose': 0.64; 'become': 0.64; 'more': 0.64; 'finally': 0.65; 'series': 0.66; 'customers': 0.66; 'invalid': 0.68; 'sound': 0.68; 'subject:One': 0.74; 'day': 0.76; 'composing': 0.84; 'from.': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Neil Cerutti <neilc@norwich.edu>
Subject Re: One liners
Date Mon, 9 Dec 2013 13:49:24 +0000 (UTC)
Organization Norwich University
References <mailman.3674.1386374070.18130.python-list@python.org> <52a282d1$0$30003$c3e8da3$5496439d@news.astraweb.com> <CAGGBd_q3rQSY=5p0DjqTC5327Kap-hDvVA8V1V_D12avp-fM3A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host jackman.norwich.edu
User-Agent slrn/0.9.9p1/mm/ao (Win32)
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.3778.1386596990.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386596990 news.xs4all.nl 2842 [2001:888:2000:d::a6]:57170
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61385

Show key headers only | View raw


On 2013-12-07, Dan Stromberg <drsalists@gmail.com> wrote:
> BTW, what's pipelining style?  Like bash?

I think, in Python, it might refer to composing your program of
a series of generators.

names = (p.name for p in db.query_people() if p.total_purchases > 0)
names = (n.upper() for n in names)
names = (n for n in names if not n.startswith("Q"))
for n in names:
   # Finally actually do something.

Coincidentally it's a nice way to break up an ugly one-liner. I
also really like that if I choose to no longer filter out
customers whose name begins with Q, I can just comment out that
one line. Try doing that with the one-liner version!

>> I'm pleased to see Python getting more popular, but it feels
>> like a lot of newcomers are trying their best to turn Python
>> into Perl or something, culturally speaking.
>
>> They're probably writing code using the idioms they are used
>> to from whatever language they have come from. Newcomers
>> nearly always do this. The more newcomers you get, the less
>> Pythonic the code you're going to see from them.
>
> Nod.

That's the sound of practicality slapping purity with a fish. A
new Python programmer can generally just get her code working in
a fairly comfortable way, then possibly rewrite it once her first
few programs become horrifying years later.

I haven't found time to rewrite all of mine yet. I still have a
program I use almost every day with an __init__ that returns
invalid objects but helpfully sets self.valid to 0.

-- 
Neil Cerutti

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


Thread

One liners Dan Stromberg <drsalists@gmail.com> - 2013-12-06 15:54 -0800
  Re: One liners Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-07 02:07 +0000
    Re: One liners Dan Stromberg <drsalists@gmail.com> - 2013-12-06 19:20 -0800
      Re: One liners Roy Smith <roy@panix.com> - 2013-12-06 22:53 -0500
      Re: One liners Steven D'Aprano <steve@pearwood.info> - 2013-12-10 03:36 +0000
    Re: One liners Neil Cerutti <neilc@norwich.edu> - 2013-12-09 13:49 +0000
    Re: One liners Chris Angelico <rosuav@gmail.com> - 2013-12-10 00:59 +1100

csiph-web