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

Comments

Your Answer

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.