How best to pass arbitrary parameters from one function to another
John O'Hagan
research at johnohagan.com
Tue Sep 30 04:58:15 EDT 2008
Hi Pythonistas,
I'm looking for the best way to pass an arbitrary number and type of variables
created by one function to another. They can't be global because they may
have different values each time they are used in the second function.
So far I'm trying to do something like this:
def process_args( [list, of, command-line, arguments] ):
do stuff
return {dictionary : of, local : variables }
def main_function( **kwargs ):
do stuff
return result
kw1 = process_args( [some, list] )
kw2 = process_args( [a, different, list] )
for i in main_function( **kw1 ):
kw2[ var1 ] = i
kw2[ var2 ] = len( i )
for j in main_function(**kw2):
print j
This only seems to work if I specify a default value for every possible
parameter of main_function and also for any others which may be passed to it,
which is a bit tedious because there are very many of them but only a few are
used in any given execution of the program.
Is there a better way to do it? Or have I simply made an error?
Regards and thanks,
John O'Hagan
More information about the Python-list
mailing list