In all of the examples, a is :
>>> def a():
... print "aaaaaaa"
I have been passed a function object from another piece of code, and I need to execute that function.
When I say “function object”, I mean an object like this:
>>> type(a)
<type 'function'>
Have a look at this:
>>> def function(f):
... print "start"
... f
... print "end"
>>> function(a)
start
end
If function() was executing the function it was passed, the output would have an aaaaaaa in the middle of it (returned from a(), which was the function passed to it)
So how can I execute a function when passed the function object?
(Sorry if this isn’t very clear, I’m confusing myself as well…)
Just call it using the function call operator
():This is how you would have called
aafter defining it. The global nameapoints to the same function object as the local namef, so you need to do the same thing to call them.