Re: [Tutor] Use of "or" in a lambda expression

2015-04-05 Thread boB Stepp
On Sun, Apr 5, 2015 at 3:06 AM, Alan Gauld wrote: > On 05/04/15 04:45, boB Stepp wrote: > > He could have done it in various other ways too: > > eg. > lambda : all(print('Hello lambda world!'), sys.exit() ) > > >> Well, now I am curious as to why the "all" form evaluates BOTH >> el

Re: [Tutor] Use of "or" in a lambda expression

2015-04-05 Thread Alan Gauld
On 05/04/15 04:45, boB Stepp wrote: He could have done it in various other ways too: eg. lambda : all(print('Hello lambda world!'), sys.exit() ) Well, now I am curious as to why the "all" form evaluates BOTH elements. Apparently it does not apply the short-circuit logic we have been discussi

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Cameron Simpson
On 04Apr2015 22:45, boB Stepp wrote: On Sat, Apr 4, 2015 at 6:55 PM, Alan Gauld wrote: lambda : all([print('Hello lambda world!'), sys.exit()] ) Well, now I am curious as to why the "all" form evaluates BOTH elements. Apparently it does not apply the short-circuit logic we have been discussi

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread boB Stepp
On Sat, Apr 4, 2015 at 6:55 PM, Alan Gauld wrote: > On 04/04/15 22:57, boB Stepp wrote: >> >> On Sat, Apr 4, 2015 at 3:35 PM, Alan Gauld >> wrote: >>> >>> He could have done it in various other ways too: >>> >>> eg. >>> lambda : all(print('Hello lambda world!'), sys.exit() ) >> >> >> Is this what

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Steven D'Aprano
On Sun, Apr 05, 2015 at 12:55:16AM +0100, Alan Gauld wrote: > On 04/04/15 22:57, boB Stepp wrote: > >On Sat, Apr 4, 2015 at 3:35 PM, Alan Gauld > >wrote: > >>He could have done it in various other ways too: > >> > >>eg. > >>lambda : all(print('Hello lambda world!'), sys.exit() ) > > > >Is this wh

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Cameron Simpson
On 05Apr2015 03:34, Steven D'Aprano wrote: On Sat, Apr 04, 2015 at 11:49:08AM -0500, boB Stepp wrote: widget = Button(None, text='Hello event world!', command=(lambda: print('Hello lambda world!') or sys.exit())) That's either the most horrible misuse of lambda I've ev

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Steven D'Aprano
On Sat, Apr 04, 2015 at 02:21:19PM -0500, boB Stepp wrote: > To my mind, would: > > def quit(): > print('Hello lambda world!') > sys.exit() > > and: > > widget = Button(None, text='Hello event world!', command=quit) > > be preferable Python style? Hell yes! Using `or` to run functio

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Alan Gauld
On 04/04/15 22:57, boB Stepp wrote: On Sat, Apr 4, 2015 at 3:35 PM, Alan Gauld wrote: He could have done it in various other ways too: eg. lambda : all(print('Hello lambda world!'), sys.exit() ) Is this what you meant? Because print will always return False. Or did you actually mean: lambda

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Mark Lawrence
On 04/04/2015 17:49, boB Stepp wrote: Windows 7, Python 3.4.3 This code snippet is "Example 7-13" on page 383 from "Programming Python, 4th ed." by Mark Lutz : import sys from tkinter import * widget = Button(None, text='Hello event world!', command=(lambda: print('He

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Dave Angel
On 04/04/2015 05:57 PM, boB Stepp wrote: On Sat, Apr 4, 2015 at 3:35 PM, Alan Gauld wrote: He could have done it in various other ways too: eg. lambda : all(print('Hello lambda world!'), sys.exit() ) Is this what you meant? Because print will always return False. Or did you actually mean: l

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread boB Stepp
On Sat, Apr 4, 2015 at 3:35 PM, Alan Gauld wrote: > He could have done it in various other ways too: > > eg. > lambda : all(print('Hello lambda world!'), sys.exit() ) Is this what you meant? Because print will always return False. Or did you actually mean: lambda: any(print('Hello lambda world!'

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Alan Gauld
On 04/04/15 17:49, boB Stepp wrote: widget = Button(None, text='Hello event world!', command=(lambda: print('Hello lambda world!') or sys.exit())) am not understanding how 'or' causes this to happen. I guess I am expecting the 'or' to result only in the print running

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Danny Yoo
> > To my mind, would: > > def quit(): > print('Hello lambda world!') > sys.exit() > > and: > > widget = Button(None, text='Hello event world!', command=quit) > > be preferable Python style? > Yes, I'd prefer this much more, compared to the original. __

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread boB Stepp
On Sat, Apr 4, 2015 at 12:34 PM, Steven D'Aprano wrote: > On Sat, Apr 04, 2015 at 11:49:08AM -0500, boB Stepp wrote: >> Windows 7, Python 3.4.3 >> >> This code snippet is "Example 7-13" on page 383 from "Programming >> Python, 4th ed." by Mark Lutz : >> >> import sys >> from tkinter import * >> >>

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread boB Stepp
On Sat, Apr 4, 2015 at 12:34 PM, Steven D'Aprano wrote: > On Sat, Apr 04, 2015 at 11:49:08AM -0500, boB Stepp wrote: >> Windows 7, Python 3.4.3 >> >> This code snippet is "Example 7-13" on page 383 from "Programming >> Python, 4th ed." by Mark Lutz : >> >> import sys >> from tkinter import * >> >>

Re: [Tutor] Use of "or" in a lambda expression

2015-04-04 Thread Steven D'Aprano
On Sat, Apr 04, 2015 at 11:49:08AM -0500, boB Stepp wrote: > Windows 7, Python 3.4.3 > > This code snippet is "Example 7-13" on page 383 from "Programming > Python, 4th ed." by Mark Lutz : > > import sys > from tkinter import * > > widget = Button(None, > text='Hello event world!', >

[Tutor] Use of "or" in a lambda expression

2015-04-04 Thread boB Stepp
Windows 7, Python 3.4.3 This code snippet is "Example 7-13" on page 383 from "Programming Python, 4th ed." by Mark Lutz : import sys from tkinter import * widget = Button(None, text='Hello event world!', command=(lambda: print('Hello lambda world!') or sys.exit())) widget