5

Sorry for the newbie question guys, but I'm relatively new to python. I want to write a function that passes keyword and value arguments into another function:

e.g.

def function_that_passes_arguments(arguments):
    some_other_function(arguments)

so when I call the first function they are passed into the second... e.g.

function_that_passes_arguments(arg1=1, arg2=2)

is effectively

some_other_function(arg1=1, arg2=2)

The argument names will change so it is important that I pass both keyword and value from one function to another.

1 Answer 1

7

Accept *args, **kwargs and pass those to the called function:

def function_that_passes_arguments(*args, **kwargs):
    some_other_function(*args, **kwargs)

In both places you can also use regular arguments - the only requirement is that the * and ** arguments are the last ones.

Sign up to request clarification or add additional context in comments.

2 Comments

In the given example, function_that_passes_arguments = some_other function would work just as well.
Yeah, but that's most likely not what @brett wants. Chances are good that there will be some code before/after the call.

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.