get function arguments

Jorge Godoy godoy at
Tue Nov 16 21:25:11 CET 2004

Steven Bethard <steven.bethard at> writes:

> Benny Mohr <news5 <at>> writes:
>> How can I get the list of argumens of this function?
> Is this what you mean?
>>>> def myFunc(a,b,c='default'):
> ... 	pass
> ... 
>>>> myFunc.func_code.co_varnames
> ('a', 'b', 'c')
> I don't know where (if?) the func_code attributes are documented, but you should
> be able to figure them out with a little object introspection (e.g. dir or an
> editor like PythonWin that does some code completion).

You could have asked in the interactive prompt as well :-)

>>> dir(myFunc.func_code)
['__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__str__', 'co_argcount', 'co_cellvars',
'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags',
'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals',
'co_stacksize', 'co_varnames']

There seems to be other interesting things here too:

>>> dir(myFunc)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
'__get__', '__getattribute__', '__hash__', '__init__', '__module__',
'__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__str__', 'func_closure', 'func_code', 'func_defaults',
'func_dict', 'func_doc', 'func_globals', 'func_name'] 

Godoy.     <godoy at>

More information about the Python-list mailing list