I am looking to pass a function to another function, as well as a named parameter. This is similar to the question asked here, except that it doesn't address named parameters. A question was asked about it in the comments but no reply.
Example:
def printPath(path, displayNumber = False):
pass
def explore(path, function, *args):
contents = function(*args)
print explore(path, printPath, path, displayNumber = False)
This gives the error:
TypeError: explore() got an unexpected keyword argument 'displayNumber'
-
A more relevant question that is already discussed - stackoverflow.com/questions/5940180/…shaktimaan– shaktimaan2014年09月07日 05:47:18 +00:00Commented Sep 7, 2014 at 5:47
1 Answer 1
You just have to allow explore to receive named parameters as well:
def printPath(path, displayNumber = False):
pass
def explore(path, function, *args, **kwargs):
contents = function(*args, **kwargs)
print explore(path, printPath, path, displayNumber = False)
answered Sep 7, 2014 at 5:52
StefanoP
3,9182 gold badges22 silver badges26 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py