Re: 1 > 0 == True -> False

2014-01-30 Thread Rustom Mody
On Friday, January 31, 2014 12:23:42 AM UTC+5:30, Roy Smith wrote: > On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: > > On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: > > > 1) Assume that you don't have the full operator precedence table > > > memorized and just paren

Re: 1 > 0 == True -> False

2014-01-30 Thread Joshua Landau
On 31 January 2014 00:10, Rotwang wrote: > > On a vaguely-related note, does anyone know why iterable unpacking in calls > was removed in Python 3? I mean things like > > def f(x, (y, z)): > return (x, y), z > > I don't have a use case in mind, I was just wondering. http://www.python.org/dev/

Removal of iterable unpacking in function calls (was: 1 > 0 == True -> False)

2014-01-30 Thread Ben Finney
Rotwang writes: > On a vaguely-related note, does anyone know why iterable unpacking in > calls was removed in Python 3? This is explained in the PEP which described its removal http://www.python.org/dev/peps/pep-3113/>, especially http://www.python.org/dev/peps/pep-3113/#why-they-should-go>. -

Re: 1 > 0 == True -> False

2014-01-30 Thread Rotwang
On 30/01/2014 23:36, Joshua Landau wrote: On 30 January 2014 20:38, Chris Angelico wrote: Why is tuple unpacking limited to the last argument? Is it just for the parallel with the function definition, where anything following it is keyword-only? You're not the first person to ask that: http:

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 10:36 AM, Joshua Landau wrote: > On 30 January 2014 20:38, Chris Angelico wrote: >> >> Why is tuple unpacking limited to the last argument? Is it just for >> the parallel with the function definition, where anything following it >> is keyword-only? > > You're not the first

Re: 1 > 0 == True -> False

2014-01-30 Thread Joshua Landau
On 30 January 2014 20:38, Chris Angelico wrote: > > Why is tuple unpacking limited to the last argument? Is it just for > the parallel with the function definition, where anything following it > is keyword-only? You're not the first person to ask that: http://www.python.org/dev/peps/pep-0448/ If

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 9:09 AM, Roy Smith wrote: > On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: >> `(x+1 > 0) and (y >= 5)` > > Me: >> this is even simpler: >> (x > -1) and (y >= 5) > > On Thursday, January 30, 2014 2:03:42 PM UTC-5, Chris Angelico wrote: >> Be careful;

Re: 1 > 0 == True -> False

2014-01-30 Thread Roy Smith
On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: > `(x+1 > 0) and (y >= 5)` Me: > this is even simpler: > (x > -1) and (y >= 5) On Thursday, January 30, 2014 2:03:42 PM UTC-5, Chris Angelico wrote: > Be careful; that's not the same thing. In what way? I'm assuming x is so

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 8:17 AM, Ian Kelly wrote: >> Why is tuple unpacking limited to the last argument? Is it just for >> the parallel with the function definition, where anything following it >> is keyword-only? > > Lack of a convincing use case, and the position of the following arguments > wo

Re: 1 > 0 == True -> False

2014-01-30 Thread Ian Kelly
On Jan 30, 2014 1:40 PM, "Chris Angelico" wrote: > > On Fri, Jan 31, 2014 at 7:28 AM, Ian Kelly wrote: > > Of course if you're at all concerned about i18n then the proper way to > > do it would be: > > > > ngettext("You have scored %d point", "You have scored %d points", score) % score > > Ugh, s

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 7:28 AM, Ian Kelly wrote: > Of course if you're at all concerned about i18n then the proper way to > do it would be: > > ngettext("You have scored %d point", "You have scored %d points", score) % > score Ugh, so much duplication! We can totally do better than that. ngett

Re: 1 > 0 == True -> False

2014-01-30 Thread Ian Kelly
On Thu, Jan 30, 2014 at 1:08 PM, Dave Angel wrote: > Rotwang Wrote in message: >> Really? I take advantage of it quite a lot. For example, I do things >> like this: >> >> 'You have scored %i point%s' % (score, 's'*(score != 1)) >> > > I also did that kind of thing when computer resources > were

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 7:14 AM, Jussi Piitulainen wrote: >> I don't think any number of parentheses will help that :-) > > Er, sorry about that. Here: > x <= y < z == w > Traceback (most recent call last): > File "", line 1, in > NameError: name 'x' is not defined > > Much better :) See,

Re: 1 > 0 == True -> False

2014-01-30 Thread Jussi Piitulainen
Roy Smith writes: > On Thursday, January 30, 2014 9:56:19 AM UTC-5, Jussi Piitulainen wrote: > > > There's nothing to parenthesize in x <= y < z = w > > Hmm > > >>> x <= y < z = w > File "", line 1 > SyntaxError: can't assign to comparison > > I don't think any number of parentheses will

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 7:08 AM, Dave Angel wrote: >> 'You have scored %i point%s' % (score, 's'*(score != 1)) >> > > Here I'd probably do something like > > 'You have scored {} {}' .format (score, 'point' if score==1 else > 'points') Bah, what's the fun in that? 'You have scored %i point%.*s'

Re: 1 > 0 == True -> False

2014-01-30 Thread Dave Angel
Rotwang Wrote in message: > On 30/01/2014 12:49, Dave Angel wrote: >> [...] >> >> For hysterical reasons, True and False are instances of class >> bool, which is derived from int. So for comparison purposes >> False==0 and True==1. But in my opinion, you should never take >> advantage of

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
Fri, Jan 31, 2014 at 6:22 AM, Ethan Furman wrote: > On 01/30/2014 11:03 AM, Chris Angelico wrote: > >> On Fri, Jan 31, 2014 at 5:56 AM, Roy Smith wrote: >>> >>> >>> Yes, that's probably how I would write that, although, this is even >>> simpler: >>> >>> (x > -1) and (y >= 5) >> >> >> Be careful;

Re: 1 > 0 == True -> False

2014-01-30 Thread Ethan Furman
On 01/30/2014 11:03 AM, Chris Angelico wrote: On Fri, Jan 31, 2014 at 5:56 AM, Roy Smith wrote: Yes, that's probably how I would write that, although, this is even simpler: (x > -1) and (y >= 5) Be careful; that's not the same thing. How so? -- ~Ethan~ -- https://mail.python.org/mailman/l

Re: 1 > 0 == True -> False

2014-01-30 Thread Rotwang
On 30/01/2014 12:49, Dave Angel wrote: [...] For hysterical reasons, True and False are instances of class bool, which is derived from int. So for comparison purposes False==0 and True==1. But in my opinion, you should never take advantage of this, except when entering obfuscation cont

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 5:56 AM, Roy Smith wrote: > On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: > >> E.g. `x+1 > 0 and y >= 5` is potentially as many as 9 distinct >> items to keep in short-term memory. But bracketing some terms >> as in `(x+1 > 0) and (y >=

Re: 1 > 0 == True -> False

2014-01-30 Thread Roy Smith
On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: > E.g. `x+1 > 0 and y >= 5` is potentially as many as 9 distinct > items to keep in short-term memory. But bracketing some terms > as in `(x+1 > 0) and (y >= 5)` can reduce that down to as few > as two items.

Re: 1 > 0 == True -> False

2014-01-30 Thread Roy Smith
On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: > On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: > > > 1) Assume that you don't have the full operator precedence table > > memorized and just parenthesize everything. > > Oh really? Do you actually write stuff like thi

Re: 1 > 0 == True -> False

2014-01-30 Thread Roy Smith
On Thursday, January 30, 2014 9:56:19 AM UTC-5, Jussi Piitulainen wrote: > There's nothing to parenthesize in x <= y < z = w Hmm >>> x <= y < z = w File "", line 1 SyntaxError: can't assign to comparison I don't think any number of parentheses will help that :-) -- https://mail.python.or

Re: 1 > 0 == True -> False

2014-01-30 Thread Mark Lawrence
On 30/01/2014 14:46, Thibault Langlois wrote: On Thursday, January 30, 2014 2:08:58 PM UTC, Roy Smith wrote: In article <3dcdc95d-5e30-46d3-b558-afedf9723...@googlegroups.com>, Thibault Langlois wrote: You are right. I should have given some context. I am looking at this from the pers

Re: 1 > 0 == True -> False

2014-01-30 Thread Rustom Mody
On Thursday, January 30, 2014 8:39:03 PM UTC+5:30, Steven D'Aprano wrote: > On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: > > 1) Assume that you don't have the full operator precedence table > > memorized and just parenthesize everything. > Oh really? Do you actually write stuff like this?

Re: 1 > 0 == True -> False

2014-01-30 Thread Steven D'Aprano
On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: > 1) Assume that you don't have the full operator precedence table > memorized and just parenthesize everything. Oh really? Do you actually write stuff like this? b = ((2*a) + 1) if (b >= (-1)): ... I would hope not. > 2) In cases wher

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 1:49 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Fri, Jan 31, 2014 at 1:08 AM, Roy Smith wrote: >> > Better than that, do what I do. >> > >> > 1) Assume that you don't have the full operator precedence table >> > memorized and just parenthesize ev

Re: 1 > 0 == True -> False

2014-01-30 Thread Jussi Piitulainen
Roy Smith writes: > In article <3dcdc95d-5e30-46d3-b558-afedf9723...@googlegroups.com>, > Thibault Langlois wrote: > > > You are right. I should have given some context. I am looking at > > this from the perspective of the teacher that has to explain > > idiosyncrasies of the language to inexpe

Re: 1 > 0 == True -> False

2014-01-30 Thread Roy Smith
In article , Chris Angelico wrote: > On Fri, Jan 31, 2014 at 1:08 AM, Roy Smith wrote: > > Better than that, do what I do. > > > > 1) Assume that you don't have the full operator precedence table > > memorized and just parenthesize everything. > > Or: > > 1a) Assume that you don't have the fu

Re: 1 > 0 == True -> False

2014-01-30 Thread Thibault Langlois
On Thursday, January 30, 2014 2:08:58 PM UTC, Roy Smith wrote: > In article <3dcdc95d-5e30-46d3-b558-afedf9723...@googlegroups.com>, > > Thibault Langlois wrote: > > > > > You are right. I should have given some context. > > > I am looking at this from the perspective of the teacher that has

Re: 1 > 0 == True -> False

2014-01-30 Thread Devin Jeanpierre
On Thu, Jan 30, 2014 at 6:08 AM, Roy Smith wrote: > 1) Assume that you don't have the full operator precedence table > memorized and just parenthesize everything. > > 2) In cases where the expression is so simple, you couldn't possibly be > wrong, see rule #1. Also, assume you don't have the func

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 1:08 AM, Roy Smith wrote: > Better than that, do what I do. > > 1) Assume that you don't have the full operator precedence table > memorized and just parenthesize everything. Or: 1a) Assume that you don't have the full operator precedence table memorized and just look it

Re: 1 > 0 == True -> False

2014-01-30 Thread Roy Smith
In article <3dcdc95d-5e30-46d3-b558-afedf9723...@googlegroups.com>, Thibault Langlois wrote: > You are right. I should have given some context. > I am looking at this from the perspective of the teacher that has to explain > idiosyncrasies of the language to inexperienced students. > There are

Re: 1 > 0 == True -> False

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 12:40 AM, Thibault Langlois wrote: > The recommendations to student are 1) do not assume True == 1 and do not use > operator chaining. Not "do not use", but "do not misuse". Python's operator chaining is awesome for bounds checking: if 3 < x < 20: print("x is between 3

Re: 1 > 0 == True -> False

2014-01-30 Thread Thibault Langlois
Type "help", "copyright", "credits" or "license" for more information. > > >>>> 1 > 0 == True > > > False > > >>>> (1 > 0) == True > > > True > > >>>> 1 > (0 == True) > > &g

Re:1 > 0 == True -> False

2014-01-30 Thread Dave Angel
Thibault Langlois Wrote in message: > Hello, > > $ python > Python 2.7.4 (default, Sep 26 2013, 03:20:26) > [GCC 4.7.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> 1 >

Re: 1 > 0 == True -> False

2014-01-30 Thread Jussi Piitulainen
Peter Otten writes: > Jussi Piitulainen wrote: > > > Thibault Langlois writes: > > > >> Hello, > >> > >> $ python > >> Python 2.7.4 (default, Sep 26 2013, 03:20:26) > >> [GCC 4.7.3] on linux2 > >> Type "help"

Re: 1 > 0 == True -> False

2014-01-30 Thread Peter Otten
Jussi Piitulainen wrote: > Thibault Langlois writes: > >> Hello, >> >> $ python >> Python 2.7.4 (default, Sep 26 2013, 03:20:26) >> [GCC 4.7.3] on linux2 >> Type "help", "copyright", "credits" or "license"

Re: 1 > 0 == True -> False

2014-01-30 Thread Jussi Piitulainen
Thibault Langlois writes: > Hello, > > $ python > Python 2.7.4 (default, Sep 26 2013, 03:20:26) > [GCC 4.7.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> 1 > 0 == True > Fal

Re: 1 > 0 == True -> False

2014-01-30 Thread Thomas Mlynarczyk
Thibault Langlois schrieb: 1 > 0 == True False What am I missing here ? This, perhaps: http://www.primozic.net/nl/chaining-comparison-operators-in-python/ Greetings, Thomas -- Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison! (Coluche) -- https

1 > 0 == True -> False

2014-01-30 Thread Thibault Langlois
Hello, $ python Python 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 1 > 0 == True False >>> (1 > 0) == True True >>> 1 > (0