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


Groups > comp.lang.python > #61385

Re: One liners

From Neil Cerutti <neilc@norwich.edu>
Subject Re: One liners
Date 2013-12-09 13:49 +0000
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>
Newsgroups comp.lang.python
Message-ID <mailman.3778.1386596990.18130.python-list@python.org> (permalink)

Show all headers | 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