Re: Eval of expr with 'or' and 'and' within

2013-06-15 Thread Nick the Gr33k
On 15/6/2013 12:48 μμ, Lele Gaifax wrote: but those 2 gives the same results back "k" in (name+month+year) == "k" in (name and month and year) True so both seem to work as expected. That happens only by chance: it seems you now understand the evaluation of "boolean" expressions in Python, so t

Re: Eval of expr with 'or' and 'and' within

2013-06-15 Thread Nick the Gr33k
On 15/6/2013 12:48 μμ, Lele Gaifax wrote: Nick the Gr33k writes: but those 2 gives the same results back "k" in (name+month+year) == "k" in (name and month and year) True so both seem to work as expected. That happens only by chance: it seems you now understand the evaluation of "boolean"

Re: Eval of expr with 'or' and 'and' within

2013-06-15 Thread Lele Gaifax
Nick the Gr33k writes: > On 15/6/2013 3:14 πμ, Cameron Simpson wrote: >> But for what you are doing, "and" and "or" are not good operations. >> >> Something like: >> >>"k" in (name+month+year) >> >> or >> >>"k" in name or "k" in month or "k" in year > > Used to wrote it myself like the la

Re: Eval of expr with 'or' and 'and' within

2013-06-15 Thread Nick the Gr33k
On 15/6/2013 3:14 πμ, Cameron Simpson wrote: On 14Jun2013 12:50, Nikos as SuperHost Support wrote: | I started another thread because the last one was !@#$'ed up by | irrelevant replies and was difficult to jeep track. | | >>> name="abcd" | >>> month="efgh" | >>> year="ijkl" | | >>> print(name o

Re: Eval of expr with 'or' and 'and' within

2013-06-15 Thread Nick the Gr33k
On 14/6/2013 7:42 μμ, Nobody wrote: Python implements these operators by returning the actual value which determined the result of the expression rather than simply True or False. which in turn the actual value being returned is a truthy or a falsey. That cleared the mystery in my head entirel

Re: Eval of expr with 'or' and 'and' within

2013-06-15 Thread Nick the Gr33k
On 15/6/2013 10:49 πμ, Denis McMahon wrote: On Sat, 15 Jun 2013 10:04:41 +0300, Nick the Gr33k wrote: I called my self 'Ferrous Cranus'(this is what a guy from a forum initially called me for being hard-headed :-) ) because i'm indeed hardheaded and if i believe that 1 thing should have worked

Re: Eval of expr with 'or' and 'and' within

2013-06-15 Thread Denis McMahon
On Sat, 15 Jun 2013 10:04:41 +0300, Nick the Gr33k wrote: > I called my self 'Ferrous Cranus'(this is what a guy from a forum > initially called me for being hard-headed :-) ) because i'm indeed > hardheaded and if i believe that 1 thing should have worked in some way > i cant change my mind easil

Re: Eval of expr with 'or' and 'and' within

2013-06-15 Thread Nick the Gr33k
On 15/6/2013 9:50 πμ, alex23 wrote: Please keep the snarky comments offlist. Tried that. He posts them back here. Alternatively, I'd ask that if you're so willing to deal with him, that the *two of you* take this show offlist instead? I'm genuinely curious as to whether he'd agree to this: gi

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread alex23
On Saturday, 15 June 2013 02:09:20 UTC+10, Steven D'Aprano wrote: > To everyone else... I know that Nikos' posts are draining. Sometimes he > brings me to the brink of despair too. But if you aren't part of the > solution, you are part of the problem: writing short-tempered, insulting > posts a

NANs [was Re: Eval of expr with 'or' and 'and' within]

2013-06-14 Thread Steven D'Aprano
On Sat, 15 Jun 2013 12:03:08 +1000, Cameron Simpson wrote: > | ... even taking that into account! *wink* | > | Everyone is aware that there is more than one NAN, right? > > I was not. Interesting. > > | If my > | calculations are correct, there are 9007199254740992 distinct float > | NANs in Pyt

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Chris Angelico
On Sat, Jun 15, 2013 at 12:03 PM, Cameron Simpson wrote: > On 15Jun2013 01:34, Steven D'Aprano > wrote: > | Everyone is aware that there is more than one NAN, right? > > I was not. Interesting. > > | If my > | calculations are correct, there are 9007199254740992 distinct float NANs > | in Python

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Cameron Simpson
On 15Jun2013 01:34, Steven D'Aprano wrote: | On Sat, 15 Jun 2013 00:09:31 +0100, Nobody wrote: | | > On Sat, 15 Jun 2013 03:56:28 +1000, Chris Angelico wrote: | >> With a few random oddities: | > bool(float("nan")) | >> True | >> I somehow expected NaN to be false. Maybe that's just my expec

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Steven D'Aprano
On Sat, 15 Jun 2013 00:09:31 +0100, Nobody wrote: > On Sat, 15 Jun 2013 03:56:28 +1000, Chris Angelico wrote: > >> With a few random oddities: >> > bool(float("nan")) >> True >> >> I somehow expected NaN to be false. Maybe that's just my expectations >> that are wrong, though. > > In gener

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Cameron Simpson
On 14Jun2013 12:50, Nikos as SuperHost Support wrote: | I started another thread because the last one was !@#$'ed up by | irrelevant replies and was difficult to jeep track. | | >>> name="abcd" | >>> month="efgh" | >>> year="ijkl" | | >>> print(name or month or year) | abcd | | Can understand t

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread MRAB
On 15/06/2013 00:06, Nobody wrote: On Fri, 14 Jun 2013 16:49:11 +, Steven D'Aprano wrote: Unlike Javascript though, Python's idea of truthy and falsey is actually quite consistent: Beyond that, if a user-defined type implements a __nonzero__() method then it determines whether an instance

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Chris Angelico
On Sat, Jun 15, 2013 at 5:33 AM, Grant Edwards wrote: > On 2013-06-14, Chris Angelico wrote: >> On Sat, Jun 15, 2013 at 3:49 AM, MRAB wrote: >>> The general rule is that an object is true-ish unless it's false-ish >>> (there are fewer false-ish objects than true-ish objects, e.g. zero vs >>> non

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Nobody
On Sat, 15 Jun 2013 03:56:28 +1000, Chris Angelico wrote: > With a few random oddities: > bool(float("nan")) > True > > I somehow expected NaN to be false. Maybe that's just my expectations > that are wrong, though. In general, you should expect the behaviour of NaN to be the opposite of w

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Nobody
On Fri, 14 Jun 2013 16:49:11 +, Steven D'Aprano wrote: > Unlike Javascript though, Python's idea of truthy and falsey is actually > quite consistent: Beyond that, if a user-defined type implements a __nonzero__() method then it determines whether an instance is true or false. If it implement

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Nobody
On Fri, 14 Jun 2013 19:30:27 +, Grant Edwards wrote: > 2. Returning one the objects that result from the evaluation of the > operands instead of returning True or False. > > This is what seems to be confusing him. This is much less common > than short-circuit evaluation. FWIW,

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Grant Edwards
On 2013-06-14, Nick the Gr33k wrote: > On 14/6/2013 7:47 , Benjamin Kaplan wrote: > In an "and" clause, >> python returns the first false value or the last value, because that >> will evaluate to the correct Boolean value. In an "or" clause, python >> returns the first true value or the last

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Grant Edwards
On 2013-06-14, Chris Angelico wrote: > On Sat, Jun 15, 2013 at 3:49 AM, MRAB wrote: >> The general rule is that an object is true-ish unless it's false-ish >> (there are fewer false-ish objects than true-ish objects, e.g. zero vs >> non-zero int). > > With a few random oddities: > bool(float

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Grant Edwards
On 2013-06-14, Nobody wrote: > On Fri, 14 Jun 2013 18:16:05 +0300, Nick the Gr33k wrote: > >> My question is why the expr (name and month and year) result in the >> value of the last variable whic is variable year? > > For much the same reason that an OR expression returns the first true > value.

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Jussi Piitulainen
Nick the Gr33k writes: > Why return first or last value? > > because that will evaluate to the correct Boolean value That value will either behave exactly the same as the Boolean value you call correct, or else it will be more useful. That is, most of the time it doesn't matter, and when it

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Joshua Landau
On 14 June 2013 19:37, rusi wrote: > 2. The recent responses from Robert Kern are in my view the ideal. In > summary it runs thus: > Stupid question no. 6457 from Nikos: ... > Robert : Look this up > Nikos: I dont understand > Robert: explains > Nikos: I DONTU NDERSTND > Robert: explains (repea

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread rusi
On Jun 14, 11:03 pm, Antoon Pardon wrote: > Op 14-06-13 18:09, Steven D'Aprano schreef: > > > > > > > > > > > On Fri, 14 Jun 2013 11:14:16 +0100, Robert Kern wrote: > > >> On 2013-06-14 10:50, Nick the Gr33k wrote: > > [snip question] > >>> This is all iw ant to know. > > >> This is all you need t

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Antoon Pardon
Op 14-06-13 18:09, Steven D'Aprano schreef: On Fri, 14 Jun 2013 11:14:16 +0100, Robert Kern wrote: On 2013-06-14 10:50, Nick the Gr33k wrote: [snip question] This is all iw ant to know. This is all you need to read: http://docs.python.org/2/reference/expressions.html#boolean- operatio

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Chris Angelico
On Sat, Jun 15, 2013 at 3:49 AM, MRAB wrote: > The general rule is that an object is true-ish unless it's false-ish > (there are fewer false-ish objects than true-ish objects, e.g. zero vs > non-zero int). With a few random oddities: >>> bool(float("nan")) True I somehow expected NaN to be fals

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread MRAB
On 14/06/2013 18:28, Michael Torrie wrote: On 06/14/2013 10:49 AM, Steven D'Aprano wrote: Correct. In Python, all boolean expressions are duck-typed: they aren't restricted to True and False, but to any "true-ish" and "false-ish" value, or as the Javascript people call them, truthy and falsey va

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Michael Torrie
On 06/14/2013 10:49 AM, Steven D'Aprano wrote: > Correct. In Python, all boolean expressions are duck-typed: they aren't > restricted to True and False, but to any "true-ish" and "false-ish" > value, or as the Javascript people call them, truthy and falsey values. > > There are a couple of anoma

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Robert Kern
On 2013-06-14 18:01, Nick the Gr33k wrote: On 14/6/2013 7:47 μμ, Benjamin Kaplan wrote: In an "and" clause, python returns the first false value or the last value, because that will evaluate to the correct Boolean value. In an "or" clause, python returns the first true value or the last value.

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Nick the Gr33k
On 14/6/2013 7:47 μμ, Benjamin Kaplan wrote: In an "and" clause, python returns the first false value or the last value, because that will evaluate to the correct Boolean value. In an "or" clause, python returns the first true value or the last value. When Python finally got a Boolean type, no o

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Steven D'Aprano
On Fri, 14 Jun 2013 10:29:25 -0600, Michael Torrie wrote: > On 06/14/2013 03:50 AM, Nick the Gr33k wrote: >> >>> print(name or month or year) >> abcd >> >>> print(name and month and year) >> ijkl > > Interesting. I'd have thought a boolean expression would return True or > False, not a string.

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Benjamin Kaplan
On Jun 14, 2013 9:34 AM, "Michael Torrie" wrote: > > On 06/14/2013 03:50 AM, Nick the Gr33k wrote: > > >>> print(name or month or year) > > abcd > > >>> print(name and month and year) > > ijkl > > Interesting. I'd have thought a boolean expression would return True or > False, not a string. Le

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Nobody
On Fri, 14 Jun 2013 18:16:05 +0300, Nick the Gr33k wrote: > My question is why the expr (name and month and year) result in the > value of the last variable whic is variable year? For much the same reason that an OR expression returns the first true value. "or" and "and" only evaluate as many a

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Michael Torrie
On 06/14/2013 03:50 AM, Nick the Gr33k wrote: > >>> print(name or month or year) > abcd > >>> print(name and month and year) > ijkl Interesting. I'd have thought a boolean expression would return True or False, not a string. Learn something new every day. -- http://mail.python.org/mailman/

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread rusi
On Jun 14, 9:09 pm, Steven D'Aprano wrote: > On Fri, 14 Jun 2013 11:14:16 +0100, Robert Kern wrote: > > On 2013-06-14 10:50, Nick the Gr33k wrote: > [snip question] > >> This is all iw ant to know. > > > This is all you need to read: > > >    http://docs.python.org/2/reference/expressions.html#boo

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Steven D'Aprano
On Fri, 14 Jun 2013 11:14:16 +0100, Robert Kern wrote: > On 2013-06-14 10:50, Nick the Gr33k wrote: [snip question] >> This is all iw ant to know. > > This is all you need to read: > >http://docs.python.org/2/reference/expressions.html#boolean- operations Thank you Robert for contributing

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Nick the Gr33k
On 14/6/2013 5:49 μμ, Grant Edwards wrote: On 2013-06-14, Nick the Gr33k wrote: I started another thread no kidding. because the last one was !@#$'ed up by irrelevant replies and was difficult to jeep track. name="abcd" month="efgh" year="ijkl" print(name or month or year) abcd Can

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Grant Edwards
On 2013-06-14, Nick the Gr33k wrote: > I started another thread no kidding. > because the last one was !@#$'ed up by irrelevant replies and was > difficult to jeep track. > > >>> name="abcd" > >>> month="efgh" > >>> year="ijkl" > > >>> print(name or month or year) > abcd > > Can understand that

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Robert Kern
On 2013-06-14 10:50, Nick the Gr33k wrote: I started another thread because the last one was !@#$'ed up by irrelevant replies and was difficult to jeep track. >>> name="abcd" >>> month="efgh" >>> year="ijkl" >>> print(name or month or year) abcd Can understand that, it takes the first stri

Re: Eval of expr with 'or' and 'and' within

2013-06-14 Thread Fábio Santos
On 14 Jun 2013 10:59, "Nick the Gr33k" wrote: > > I started another thread because the last one was !@#$'ed up by irrelevant replies and was difficult to jeep track. > > >>> name="abcd" > >>> month="efgh" > >>> year="ijkl" > > >>> print(name or month or year) > abcd > > Can understand that, it tak