Re: Code formatting question: conditional expression

2009-08-26 Thread Ben Finney
Nicola Larosa (tekNico) nicola.lar...@gmail.com 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

Re: Code formatting question: conditional expression

2009-08-26 Thread Jorgen Grahn
On Wed, 26 Aug 2009 16:47:33 +1000, Ben Finney ben+pyt...@benfinney.id.au wrote: Nicola Larosa (tekNico) nicola.lar...@gmail.com writes: Nicola Larosa wrote: Here's my take:     excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True         ) if total P.BASE else None

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-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, I

Re: Code formatting question: conditional expression

2009-08-21 Thread Aahz
In article 87ocqchl2k@benfinney.id.au, Ben Finney ben+pyt...@benfinney.id.au wrote: Diez B. Roggisch de...@nospam.web.de 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

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 cond

Re: Code formatting question: conditional expression

2009-08-19 Thread Bruno Desthuilliers
Richard Brodie a écrit : John Posner jjpos...@optimum.net 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

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

Code formatting question: conditional expression

2009-08-18 Thread John Posner
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 on how to format a conditional expression that

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 on how to

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 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 = None

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. Thanks

Re: Code formatting question: conditional expression

2009-08-18 Thread Richard Brodie
John Posner jjpos...@optimum.net 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

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

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

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 Jan Kaliszewski
18-08-2009 Steven D'Aprano st...@remove-this-cybersource.com.au 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

Re: Code formatting question: conditional expression

2009-08-18 Thread Ben Finney
John Posner jjpos...@optimum.net 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

Re: Code formatting question: conditional expression

2009-08-18 Thread Ben Finney
Diez B. Roggisch de...@nospam.web.de 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

Re: Code formatting question: conditional expression

2009-08-18 Thread John Yeung
On Aug 18, 1:25 pm, John Posner jjpos...@optimum.net 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