How best to pass arbitrary parameters from one function to another



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
.



Relevant Pages

  • Re: Scots Executed after Jacobite Rebellion?
    ... alternative to trial and possible execution if they admitted guilt without ... refused the option of transportation. ... "John Arbuthnot and 747 others were pardoned on condition of transportation ... and four others recieved a free pardon" ...
    (soc.culture.scottish)
  • Re: Steve Carroll proves he cannot understand what he reads. Again.
    ... Yup, and they show that both you and John are "very, very" confused. ... "Steve has an unsupported eSata card in his machine for one thing". ... "John responded to a comment about "Macs" by referencing a specific ... "That John's reply to the comment about "Macs" does not specify ...
    (comp.sys.mac.advocacy)
  • RE: [PHP] using mail() - what is max number of email addresses I can specify in To field?
    ... want to start with "Good Afternoon John" for a mail to a fella named John), ... Or even better, specify something like ... It really depends on the mta you use... ... >Do you Yahoo!? ...
    (php.general)
  • Re: DRIVES
    ... You can specify any Drive\folder as the location for your ... captured video as John said. ... Windows XP Media Center Edition ...
    (microsoft.public.windowsxp.moviemaker)
  • Re: need help with Now()
    ... so the Eurpean interzone time differences are constant. ... [John S., our time guru, will correct me if and where I am wrong.] ... and not specify that you wanted a imprecise answer? ...
    (microsoft.public.scripting.vbscript)