Re: [Tutor] Passing functions as arguments to other functions

2016-09-30 Thread Ben Finney
boB Stepp writes: > I think this was my key point of confusion. I was mistakenly thinking > of f(x) as referring to the function object. Right. ‘f’ is an expression, that Python resolves as whatever object ‘f’ references. ‘f(x)’ is an expression, that Python resolves by *calling* the object r

Re: [Tutor] Passing functions as arguments to other functions

2016-09-30 Thread boB Stepp
On Fri, Sep 30, 2016 at 6:55 AM, Steven D'Aprano wrote: > On Thu, Sep 29, 2016 at 09:43:57PM -0500, boB Stepp wrote: >> But why does Python require >> separating the function object from its parameters when it is being >> passed as an argument to another function? > > If you pass the function arg

Re: [Tutor] Passing functions as arguments to other functions

2016-09-30 Thread boB Stepp
On Fri, Sep 30, 2016 at 3:43 AM, Alan Gauld via Tutor wrote: > On 30/09/16 03:43, boB Stepp wrote: > >> Also, I note that if I just type a function name without the >> parentheses in the interpreter, I will get something like this: >> > def f(): >>pass >> > f >> >> >> So the i

Re: [Tutor] Passing functions as arguments to other functions

2016-09-30 Thread Steven D'Aprano
On Fri, Sep 30, 2016 at 09:43:47AM +0100, Alan Gauld via Tutor wrote: > On 30/09/16 03:43, boB Stepp wrote: > > > Also, I note that if I just type a function name without the > > parentheses in the interpreter, I will get something like this: > > > def f(): > >pass > > > f

Re: [Tutor] Passing functions as arguments to other functions

2016-09-30 Thread Steven D'Aprano
On Thu, Sep 29, 2016 at 09:43:57PM -0500, boB Stepp wrote: > I believe I understand the barebone mechanics on how to do this. But > I do not understand the rationale of why Python does it the way it > does. Say > > def f(g, *args): > g(*args) Right. This says: - Define a function called "

Re: [Tutor] Passing functions as arguments to other functions

2016-09-30 Thread Alan Gauld via Tutor
On 30/09/16 03:43, boB Stepp wrote: > Also, I note that if I just type a function name without the > parentheses in the interpreter, I will get something like this: > def f(): >pass > f > > > So the impression I am getting is that a function name by itself (with > no pare

Re: [Tutor] Passing functions as arguments to other functions

2016-09-29 Thread Ben Finney
boB Stepp writes: > So the impression I am getting is that a function name by itself (with > no parentheses) is the function *object*. Yes. The expression ‘func’ resolves to whatever object is referenced by that name; if it's a function object, you get that object. The expression ‘func(foo, bar