Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you pass arguments from one function to another?

Tags:

python

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.

like image 372
brett Avatar asked Nov 29 '12 18:11

brett


1 Answers

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.

like image 158
ThiefMaster Avatar answered Oct 15 '22 22:10

ThiefMaster