arguments to functions

holger krekel pyth at devel.trillke.net
Sun Jun 30 13:10:06 EDT 2002


Uwe Mayer wrote:
> hi,
> 
> I wanted to pass one named and a collection of unnamed (an arbitrary 
> number) to a function:
> 
> def test(expected=None, *misc):
>     print(expected)
>     print(misc)
> 
> Now, unluckyly 'test' interprets the first unnamed parameter to test as 
> the value for 'expected'

which is expected (and obviously you want to have a double **). 
Or what did you expect? 

You can easily do:

    def test(**kwargs):
        expected = kwargs.get('expected',None)

the dictionaries' get method returns None if it doesn't have 'expected'
as a key.

HTH,

    holger





More information about the Python-list mailing list