get function arguments

Steven Bethard steven.bethard at
Tue Nov 16 21:46:28 CET 2004

Batista, Facundo <FBatista <at>> writes:
> [Steven Bethard]
> #- >>> def myFunc(a,b,c='default'):
> #- ...  pass
> #- ...
> #- >>> myFunc.func_code.co_varnames
> #- ('a', 'b', 'c')
> #- 
> How do you do that from *inside* the function?

I'm not clear exactly what it is you're looking to do here -- could you
elaborate?  If you're writing the function yourself, don't you know what
arguments you wrote up in the def statement?

I'm hesitant to guess what it is you intend, but if you're just looking for the
string names, this might work for you:

>>> def myFunc(a,b,c='default'):
... 	print locals().keys()
>>> myFunc(1, 2)
['a', 'c', 'b']

My guess though is that if this is what you want, you might have a design
problem there...  You should also be wary that this only really works in the
first line of the function (or at least until you create another name in the


More information about the Python-list mailing list