Function arguments

Erik Max Francis max at alcyone.com
Mon Jan 26 04:09:34 EST 2009


brasse wrote:

> Is there any way that I can get at all the arguments passed to a
> function as a map without using keyword arguments?
> 
> def foo(a, b, c):
>     # Can I access all the arguments in a collection somewhere?
> 
> I'm mainly curious since I have stumbled on to some cases where it
> might have been nice to be able to do that.

Look up the function call syntaxes with * and **:

 >>> def foo(*args): print args
...
 >>> def bar(**keywords): print keywords
...
 >>> foo(1, 2, 3)
(1, 2, 3)
 >>> bar(a=1, b=2, c=3)
{'a': 1, 'c': 3, 'b': 2}

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   Custom reconciles us to everything.
    -- Edmund Burke



More information about the Python-list mailing list