simplebeginnerquestion(**args)

Fredrik Lundh fredrik at pythonware.com
Sun Jul 25 17:09:13 EDT 1999


using a bogus mail address, "optional (Brian)" wrote:
> I'm trying to figure out how to use the (**args) thing. I can manage
> to pass an arbitrary # of arguments to a function with (*stuff) as a
> tuple, but if I use (**stuff)  to do it like this:
> 
> myfunc(**stuff):
>  for i in stuff.keys():
>   print i 
> 
> myfunc(1,2,3,4)
> 
> the interpreter raises an error saying it expected..0 arguments and
> got..4 if I use (*stuff) (without .keys()...) it works. 
> Shouldn't (**stuff) cause a dictionary filled with myfunc(stuff here)
> to happen and the 'print i' print up the keys?

interesting. what did you expect the "keys" to
be in this case?

> What I don't get is why does it expect..0 arguments? Why doesn't it
> realize that there is a ** there?

reading the manual might help:

    If the form ``**identifier'' is present, it is initialized
    to a new dictionary receiving any excess keyword
    arguments.

if you don't pass the function any keyword arguments
at all, there are obviously no excess keyword arguments
to put in that dictionary...

</F>





More information about the Python-list mailing list