1

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'
asked Sep 7, 2014 at 5:42
1

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.