How best to pass arbitrary parameters from one function to another
- From: John O'Hagan <research@xxxxxxxxxxxxxx>
- Date: Tue, 30 Sep 2008 08:58:15 +0000
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
.
- Follow-Ups:
- Re: How best to pass arbitrary parameters from one function to another
- From: Steven D'Aprano
- Re: How best to pass arbitrary parameters from one function to another
- From: Bruno Desthuilliers
- Re: How best to pass arbitrary parameters from one function to another
- Prev by Date: Re: Python is slow?
- Next by Date: Re: Python is slow?
- Previous by thread: Re: Python script for tracert
- Next by thread: Re: How best to pass arbitrary parameters from one function to another
- Index(es):
Relevant Pages
|