Re: [Tutor] Functional Programming in Python

2015-04-04 Thread Steven D'Aprano
On Sat, Apr 04, 2015 at 09:53:28PM -0400, WolfRage wrote: > > So I was surprised I did not get more feedback on my abused coroutine, > maybe that is good or bad, not sure. Perhaps people didn't understand it. Or see it :-) > Any ways I am on to trying to make that coroutine act more like the >

Re: [Tutor] Functional Programming in Python

2015-04-04 Thread Dave Angel
On 04/04/2015 09:53 PM, WolfRage wrote: (Pointing to the different classes. Since C++ has virtual methods but Python does not?) I'd say that all methods in Python are virtual, except for those which are classmethod or staticmethod. -- DaveA _

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] Functional Programming in Python

2015-04-04 Thread Steven D'Aprano
On Thu, Apr 02, 2015 at 12:18:28PM -0400, WolfRage wrote: > These are just some questions that I have regarding the topic of > Functional Programming. I am working towards a more functional approach > to programming but acknowledge that it is far from Functional, > especially since this is mostl

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] Functional Programming in Python

2015-04-04 Thread WolfRage
So I was surprised I did not get more feedback on my abused coroutine, maybe that is good or bad, not sure. Any ways I am on to trying to make that coroutine act more like the State Pattern from Gang of Four. And well reading this: http://gameprogrammingpatterns.com/state.html I am not sure ho

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] Request review: A DSL for scraping a web page

2015-04-04 Thread boB Stepp
On Thu, Apr 2, 2015 at 2:49 PM, Albert-Jan Roskam wrote: > > - > On Thu, Apr 2, 2015 1:17 PM CEST Alan Gauld wrote: > >>On 02/04/15 12:09, Dave Angel wrote: >> >>> Ah, Jon Bentley (notice the extra 'e'). I should dig out my *Pearls >>> books, and have a trip down memor

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

Re: [Tutor] Request review: A DSL for scraping a web page

2015-04-04 Thread Joe Farro
Joe Farro gmail.com> writes: > indentation doesn't (always) reflect the hierarchy of the data being > generated, which seems more clear. Meant to say: However, the indentation doesn't (always) reflect the hierarchy of the data being generated, which seems more clear **in the bs4 version**. __

Re: [Tutor] Request review: A DSL for scraping a web page

2015-04-04 Thread Joe Farro
Joe Farro gmail.com> writes: > > Thanks, Peter. > > Peter Otten <__peter__ web.de> writes: > > > Can you give a real-world example where your DSL is significantly cleaner > > than the corresponding code using bs4, or lxml.xpath, or lxml.objectify? Peter, I worked up what I hope is a fairly