I know when using Groovy closures, I can change the delegate
on the closure so function calls made within the closure could be defined externally.
Can I do something similar in Python?
Specifically, if you take the following code:
def configure():
build()
def wrap(function):
def build():
print 'build'
function()
wrap(configure)
I'd like it to print 'build' (only making changes to wrap()
).
Some notes:
I don't want to pass functions into configure()
since there may be a large number of functions that can be called by configure()
.
I also don't want to define those globally, because, once again, there may be a large number of functions that can be called by configure()
and I don't want to pollute the global namespace.