Re: Code formatting question: conditional expression

2009-08-26 Thread Jorgen Grahn
On Wed, 26 Aug 2009 16:47:33 +1000, Ben Finney wrote: > "Nicola Larosa (tekNico)" writes: > >> Nicola Larosa wrote: >> > Here's my take: >> > >> >     excessblk = Block(total - P.BASE, srccol, >> > carry_button_suppress=True >> >         ) if total > P.BASE else None >> >> Oops, it got shortened

Re: Code formatting question: conditional expression

2009-08-25 Thread Ben Finney
"Nicola Larosa (tekNico)" writes: > Nicola Larosa wrote: > > Here's my take: > > > >     excessblk = Block(total - P.BASE, srccol, > > carry_button_suppress=True > >         ) if total > P.BASE else None > > Oops, it got shortened out: line longer than 72 chars, acceptable in > code, but not in e

Re: Code formatting question: conditional expression

2009-08-25 Thread Nicola Larosa (tekNico)
Nicola Larosa wrote: > Here's my take: > >     excessblk = Block(total - P.BASE, srccol, > carry_button_suppress=True >         ) if total > P.BASE else None Oops, it got shortened out: line longer than 72 chars, acceptable in code, but not in email. I'll try again. If the first line is too long,

Re: Code formatting question: conditional expression

2009-08-25 Thread Nicola Larosa (tekNico)
John Posner wrote: > Is there any consensus on how to format a conditional expression > that is too long for one line? Here's my take: excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True ) if total > P.BASE else None -- Nicola Larosa - http://www.tekNico.net/ Nobody

Re: Code formatting question: conditional expression

2009-08-21 Thread Aahz
In article <87ocqchl2k@benfinney.id.au>, Ben Finney wrote: >"Diez B. Roggisch" writes: >> >> excessblk = None >> if total > P.BASE: >> excessblk = ... >> >> You don't lose any vertical space, > >I don't see vertical space as such a scarce resource; we don't have an >imminent newline shor

Re: Code formatting question: conditional expression

2009-08-19 Thread John Posner
Diez wrote: No. I love them. But not if they are so large that they stretch over several lines (or to many columns). foo = bar if cond else baz is more than fine for me. But foo = I_need_to_do_something_really_complicated_here() if cond else baz isn't, because one doesn't grasp as easily in

Re: Code formatting question: conditional expression

2009-08-19 Thread Bruno Desthuilliers
Richard Brodie a écrit : "John Posner" wrote in message news:mailman.26.1250604346.2854.python-l...@python.org... if total > P.BASE: excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True) else: excessblk = None I wonder if it is appropriate to replace the None sen

Re: Code formatting question: conditional expression

2009-08-19 Thread Diez B. Roggisch
> BTW, from the (admittedly few) responses to my original post, it seems > there's some sentiment that "conditional expressions" are a non-Pythonic > misfeature. Interesting ... No. I love them. But not if they are so large that they stretch over several lines (or to many columns). foo = bar if

Re: Code formatting question: conditional expression

2009-08-18 Thread John Yeung
On Aug 18, 1:25 pm, John Posner wrote: > BTW, from the (admittedly few) responses to my original > post, it seems there's some sentiment that "conditional > expressions" are a non-Pythonic misfeature. Interesting ... Well, it's not like Guido was especially eager to add it in the first place. I

Re: Code formatting question: conditional expression

2009-08-18 Thread Ben Finney
John Posner writes: > > excessblk = None > > if total > P.BASE: > > excessblk = ... > > […] > But doesn't it violate the DRY principle? The token "excessblk" > appears twice instead of once. No, the DRY principle http://c2.com/cgi/wiki?DontRepeatYourself> doesn't speak against assigning two

Re: Code formatting question: conditional expression

2009-08-18 Thread Ben Finney
"Diez B. Roggisch" writes: > excessblk = None > if total > P.BASE: > excessblk = ... > > You don't lose any vertical space, I don't see vertical space as such a scarce resource; we don't have an imminent newline shortage, to my knowledge. I value it far lower than, say, local readability. >

Re: Code formatting question: conditional expression

2009-08-18 Thread Ben Finney
John Posner writes: > Is there any consensus on how to format a conditional expression that > is too long for one line? How about this: > > excessblk = (Block(total - P.BASE, srccol, carry_button_suppress=True) > if total > P.BASE else > None) > > The above format sep

Re: Code formatting question: conditional expression

2009-08-18 Thread Jan Kaliszewski
18-08-2009 Steven D'Aprano wrote: On Tue, 18 Aug 2009 10:04:36 -0400, John Posner wrote: [snip] How about this: excessblk = (Block(total - P.BASE, srccol, carry_button_suppress=True) if total > P.BASE else None) If you insist on using the conditional expres

Re: Code formatting question: conditional expression

2009-08-18 Thread Ethan Furman
John Posner wrote: BTW, from the (admittedly few) responses to my original post, it seems there's some sentiment that "conditional expressions" are a non-Pythonic misfeature. Interesting ... -John I didn't read it that way. One of the (to me) core points of Pythonic is readability. A

Re: Code formatting question: conditional expression

2009-08-18 Thread John Posner
I wonder if it is appropriate to replace the None sentinel with one that is an instance of Block() e.g. size = total - P.BASE excessblk = Block(size, srccol, carry_button_suppress=True, empty_block=(size <= 0) ) In this particular case, Richard, I don't think so. The Block class is an a

Re: Code formatting question: conditional expression

2009-08-18 Thread Jean-Michel Pichavant
John Posner wrote: My choice would be excessblk = None if total > P.BASE: excessblk = ... Diez and Jean-Michel, Ha! Your suggestion above was my *original* coding. It looks like I'm evolving backwards! But doesn't it violate the DRY principle? The token "excessblk" appears twice ins

Re: Code formatting question: conditional expression

2009-08-18 Thread Richard Brodie
"John Posner" wrote in message news:mailman.26.1250604346.2854.python-l...@python.org... > if total > P.BASE: > excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True) > else: > excessblk = None I wonder if it is appropriate to replace the None sentinel with one that

Re: Code formatting question: conditional expression

2009-08-18 Thread John Posner
My choice would be excessblk = None if total > P.BASE: excessblk = ... Diez and Jean-Michel, Ha! Your suggestion above was my *original* coding. It looks like I'm evolving backwards! But doesn't it violate the DRY principle? The token "excessblk" appears twice instead of once. Than

Re: Code formatting question: conditional expression

2009-08-18 Thread Steven D'Aprano
On Tue, 18 Aug 2009 10:04:36 -0400, John Posner wrote: > While refactoring some code, I ran across an opportunity to use a > conditional expression. Original: > > if total > P.BASE: > excessblk = Block(total - P.BASE, srccol, > carry_button_suppress=True) > else: > excessblk

Re: Code formatting question: conditional expression

2009-08-18 Thread Jean-Michel Pichavant
Diez B. Roggisch wrote: John Posner wrote: While refactoring some code, I ran across an opportunity to use a conditional expression. Original: if total > P.BASE: excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True) else: excessblk = None Is there any

Re: Code formatting question: conditional expression

2009-08-18 Thread Diez B. Roggisch
John Posner wrote: > While refactoring some code, I ran across an opportunity to use a > conditional expression. Original: > > if total > P.BASE: > excessblk = Block(total - P.BASE, srccol, > carry_button_suppress=True) > else: > excessblk = None > > Is there any consensus