Re: One liners

2013-12-09 Thread Steven D'Aprano
On Fri, 06 Dec 2013 19:20:07 -0800, Dan Stromberg wrote: > On Fri, Dec 6, 2013 at 6:07 PM, Steven D'Aprano < > steve+comp.lang.pyt...@pearwood.info> wrote: >> The beauty of Python is that it is a multi-paradigm language. You can >> write imperative, procedural, functional, OOP, or pipelining styl

Re: One liners

2013-12-09 Thread Chris Angelico
On Tue, Dec 10, 2013 at 12:49 AM, Neil Cerutti wrote: > 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

Re: One liners

2013-12-09 Thread Neil Cerutti
On 2013-12-07, Dan Stromberg 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 name

Re: One liners

2013-12-07 Thread Rotwang
On 07/12/2013 16:25, Steven D'Aprano wrote: On Sat, 07 Dec 2013 16:13:09 +, 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:

Re: One liners

2013-12-07 Thread bryan rasmussen
Someone was thinking in ruby there. On Sat, Dec 7, 2013 at 1:14 AM, Dan Stromberg wrote: > > On Fri, Dec 6, 2013 at 4:10 PM, Michael Torrie wrote: > >> On 12/06/2013 04:54 PM, Dan Stromberg wrote: >> > Does anyone else feel like Python is being dragged too far in the >> direction >> > of long

Re: One liners

2013-12-07 Thread Mark Lawrence
On 06/12/2013 23:54, Dan Stromberg wrote: Does anyone else feel like Python is being dragged too far in the direction of long, complex, multiline one-liners? Or avoiding temporary variables with descriptive names? Or using regex's for everything under the sun? What happened to using classes?

Re: One liners

2013-12-07 Thread Terry Reedy
On 12/7/2013 11: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

Re: One liners

2013-12-07 Thread Jussi Piitulainen
Rotwang writes: > 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 > >

Re: One liners

2013-12-07 Thread rusi
On Saturday, December 7, 2013 10:26:04 PM UTC+5:30, Michael Torrie wrote: > On 12/06/2013 08:27 PM, Roy Smith wrote: > > Steven D'Aprano wrote: > >> The ternary if is slightly unusual and unfamiliar > > It's only unusual an unfamiliar if you're not used to using it :-) > > Coming from a C/C++ b

Re: One liners

2013-12-07 Thread Michael Torrie
On 12/07/2013 09:56 AM, Michael Torrie wrote: >> extracols = sorted(set.union(*(set(t.data.keys()) for t in tracks))) if >> tracks else [] > > This is a generator expressions, and ternary ifs are common and often > needed in generator expressions. Oops. This is not a generator expression at all!

Re: One liners

2013-12-07 Thread Michael Torrie
On 12/06/2013 08:27 PM, Roy Smith wrote: > In article <52a287cb$0$30003$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: > >> The ternary if is slightly unusual and unfamiliar > > It's only unusual an unfamiliar if you're not used to using it :-) > Coming from a C/C++ background,

Re: One liners

2013-12-07 Thread Steven D'Aprano
On Sat, 07 Dec 2013 16:13:09 +, 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 t

Re: One liners

2013-12-07 Thread Michael Torrie
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 Non

Re: One liners

2013-12-07 Thread Rotwang
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

Re: One liners

2013-12-07 Thread Jussi Piitulainen
Steven D'Aprano writes: > On Fri, 06 Dec 2013 22:27:00 -0500, Roy Smith wrote: > > > Just for fun, I took a look through the Songza code base. 66 kloc of > > non-whitespace Python. I found 192 ternary expressions. Here's a few > > of the more bizarre ones (none of which I consider remotely rea

Re: One liners

2013-12-07 Thread Steven D'Aprano
On Fri, 06 Dec 2013 22:27:00 -0500, Roy Smith wrote: > Just for fun, I took a look through the Songza code base. 66 kloc of > non-whitespace Python. I found 192 ternary expressions. Here's a few > of the more bizarre ones (none of which I consider remotely readable): > > --

Re: One liners

2013-12-06 Thread Chris Angelico
On Sat, Dec 7, 2013 at 2:27 PM, Roy Smith wrote: > -- > extracols = sorted(set.union(*(set(t.data.keys()) for t in tracks))) if > tracks else [] > -- > c2s = compids2songs(set(targets.keys()) | > set.un

Re: One liners

2013-12-06 Thread Roy Smith
In article , Dan Stromberg wrote: > A lot of things people do with regex's, could be done with string methods > more clearly and concisely. That is true. The problem is, there are a lot of things for which regex is the right tool, but people get out of practice using them (or never learned h

Re: One liners

2013-12-06 Thread Roy Smith
In article <52a287cb$0$30003$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > The ternary if is slightly unusual and unfamiliar It's only unusual an unfamiliar if you're not used to using it :-) Coming from a C/C++ background, I always found the lack of a ternary expression rath

Re: One liners

2013-12-06 Thread Dan Stromberg
On Fri, Dec 6, 2013 at 6:07 PM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Fri, 06 Dec 2013 15:54:22 -0800, Dan Stromberg wrote: > > > Does anyone else feel like Python is being dragged too far in the > > direction of long, complex, multiline one-liners? Or avoiding tempo

Re: One liners

2013-12-06 Thread Chris Angelico
On Sat, Dec 7, 2013 at 1:28 PM, Steven D'Aprano wrote: > As for readability, I accept that ternary if is unusual compared to other > languages... All the C-derived ternary operators put the condition first, but Python puts the condition in the middle. What that does for readability I don't really

Re: One liners

2013-12-06 Thread Steven D'Aprano
On Fri, 06 Dec 2013 17:20:27 -0700, Michael Torrie wrote: > On 12/06/2013 05:14 PM, Dan Stromberg wrote: >> I'm thinking mostly of stackoverflow, but here's an example I ran into >> (a lot of) on a job: >> >> somevar = some_complicated_thing(somevar) if >> some_other_complicated_thing(somevar) el

Re: One liners

2013-12-06 Thread Steven D'Aprano
On Fri, 06 Dec 2013 15:54:22 -0800, Dan Stromberg wrote: > Does anyone else feel like Python is being dragged too far in the > direction of long, complex, multiline one-liners? Or avoiding temporary > variables with descriptive names? Or using regex's for everything under > the sun? All those t

Re: One liners

2013-12-06 Thread Roy Smith
In article , Joel Goldstick wrote: > Aside from django urls, I am not sure I ever wrote regexes in python. For > some reason they must seem awfully sexy to quite a few people. Back to my > point above -- ever try to figure out a complicated regex written by > someone else? Regex has a bad rap

Re: One liners

2013-12-06 Thread Joel Goldstick
On Fri, Dec 6, 2013 at 7:20 PM, Michael Torrie wrote: > On 12/06/2013 05:14 PM, Dan Stromberg wrote: > > I'm thinking mostly of stackoverflow, but here's an example I ran into (a > > lot of) on a job: > > > > somevar = some_complicated_thing(somevar) if > > some_other_complicated_thing(somevar) e

Re: One liners

2013-12-06 Thread Michael Torrie
On 12/06/2013 05:14 PM, Dan Stromberg wrote: > I'm thinking mostly of stackoverflow, but here's an example I ran into (a > lot of) on a job: > > somevar = some_complicated_thing(somevar) if > some_other_complicated_thing(somevar) else somevar > > Would it really be so bad to just use an if statem

Re: One liners

2013-12-06 Thread Dan Stromberg
On Fri, Dec 6, 2013 at 4:10 PM, Michael Torrie wrote: > On 12/06/2013 04:54 PM, Dan Stromberg wrote: > > Does anyone else feel like Python is being dragged too far in the > direction > > of long, complex, multiline one-liners? Or avoiding temporary variables > > with descriptive names? Or using

Re: One liners

2013-12-06 Thread Michael Torrie
On 12/06/2013 04:54 PM, Dan Stromberg wrote: > Does anyone else feel like Python is being dragged too far in the direction > of long, complex, multiline one-liners? Or avoiding temporary variables > with descriptive names? Or using regex's for everything under the sun? > > What happened to using

Re: One liners

2013-12-06 Thread Ned Batchelder
On 12/6/13 6:54 PM, Dan Stromberg wrote: Does anyone else feel like Python is being dragged too far in the direction of long, complex, multiline one-liners? Or avoiding temporary variables with descriptive names? Or using regex's for everything under the sun? What happened to using classes?