pythonparametersargumentspositional-argument

Calling out positional argument


I have a python 2.5 function with a definition like:

def Foo(a, b='Silly', c='Walks', d='Spam', e='Eggs', f='Ni', *addl):

Where addl can be any number of strings (filenames) to do something with.

I'm fine with all of the defaults, but I have filenames to put in addl.

I am inclined to do something like:

Foo('me@domain.com', addl=('File1.txt', 'File2.txt'))

But that gets the following error:

TypeError: Foo() got an unexpected keyword argument 'addl'

Is there a syntax where I can succinctly call Foo with just the first required parameter and my (variable number of) additional strings? Or am I stuck redundantly specifying all of the defaults before I can break into the addl argument range?

For the sake of argument, the function definition is not able to be modified or refactored.


Solution

  • Ok, if function can't be modified, then why not create wrapper?

    def foo_with_defaults(a, *addl):
        Foo(a, *(Foo.func_defaults + addl))
    
    foo_with_defaults('me@domain.com', *('File1.txt', 'File2.txt'))