Re: [Tutor] evaluating AND

2007-09-14 Thread Ricardo Aráoz
Orest Kozyar wrote: > Given a variable x that can either be None or a tuple of two floats [i.e. > (0.32, 4.2)], which syntax is considered most appropriate under Python > coding standards? > > if x and x[0] > 0: > pass > > =OR= > > if x: > if x[0] > 0: > pass >

Re: [Tutor] evaluating AND

2007-09-14 Thread Terry Carroll
On Fri, 14 Sep 2007, Rikard Bosnjakovic wrote: > For me, "if x" would be enough. If you think it's a bad thing when x > is of the wrong data, then you really should check that it contains > *correct* data as well. That's an okay approach, but, but it's also non-Pythoninc; more of the look-before

Re: [Tutor] evaluating AND

2007-09-13 Thread John Fouhy
On 14/09/2007, Rikard Bosnjakovic <[EMAIL PROTECTED]> wrote: > On 14/09/2007, Terry Carroll <[EMAIL PROTECTED]> wrote: > > The second one, which just checks "if x" and is satisfied with any false > > value, including an empty tuple, does not raise the error condition, even > > though the data is ba

Re: [Tutor] evaluating AND

2007-09-13 Thread Rikard Bosnjakovic
On 14/09/2007, Terry Carroll <[EMAIL PROTECTED]> wrote: > The second one, which just checks "if x" and is satisfied with any false > value, including an empty tuple, does not raise the error condition, even > though the data is bad. This is a bad thing. For me, "if x" would be enough. If you thi

Re: [Tutor] evaluating AND

2007-09-13 Thread Terry Carroll
On Thu, 13 Sep 2007, Adam Bark wrote: > The problem is what if it's an empty list or tuple? It would pass but have > not value > whereas if x would work fine. Exactly. The poster stated that x is supposed to be either None or a tuple of two floats. Just to put a bit of meat on the example, let

Re: [Tutor] evaluating AND

2007-09-13 Thread Adam Bark
On 13/09/2007, Terry Carroll <[EMAIL PROTECTED]> wrote: > > On Thu, 13 Sep 2007, Orest Kozyar wrote: > > > Given a variable x that can either be None or a tuple of two floats [i.e > . > > (0.32, 4.2)], which syntax is considered most appropriate under Python > > coding standards? > > > > if x and x

Re: [Tutor] evaluating AND

2007-09-13 Thread Kent Johnson
Orest Kozyar wrote: > Given a variable x that can either be None or a tuple of two floats [i.e. > (0.32, 4.2)], which syntax is considered most appropriate under Python > coding standards? > > if x and x[0] > 0: > pass > > =OR= > > if x: > if x[0] > 0: > pass T

Re: [Tutor] evaluating AND

2007-09-13 Thread Terry Carroll
On Thu, 13 Sep 2007, Orest Kozyar wrote: > Given a variable x that can either be None or a tuple of two floats [i.e. > (0.32, 4.2)], which syntax is considered most appropriate under Python > coding standards? > > if x and x[0] > 0: > pass > > =OR= > > if x: > if x[0] > 0: >

Re: [Tutor] evaluating AND

2007-09-13 Thread Eric Brunson
The first is how I would code it. Python guarantees that compound boolean statements are processed from left to right and also that the AND operator will "short circuit" the rest of the evaluation, since the rest of the line cannot change the falseness of the entire statement. Orest Kozyar wr

[Tutor] evaluating AND

2007-09-13 Thread Orest Kozyar
Given a variable x that can either be None or a tuple of two floats [i.e. (0.32, 4.2)], which syntax is considered most appropriate under Python coding standards? if x and x[0] > 0: pass =OR= if x: if x[0] > 0: pass In the first, I'm obviously making the