number of function arguments

Giorgi Lekishvili gleki at gol.ge
Fri Dec 27 09:19:47 EST 2002


Thx!
Giorgi

Justin Shaw wrote:

> > I have encountered such a problem. Suppose I have a some function. How
> > can I get the number of its arguments?
> > Giorgi
> >
>
> Giorgi,
> First thing I always try with questions like this is searching around with
> dir().
> Justin
>
> >>> def f(x):
>  print x
>
>  >>> dir(f)
> ['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__',
> '__getattribute__', '__hash__', '__init__', '__name__', '__new__',
> '__reduce__', '__repr__', '__setattr__', '__str__', 'func_closure',
> 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals',
> 'func_name']
> >>> dir(f.func_code)
> ['__class__', '__cmp__', '__delattr__', '__getattribute__', '__hash__',
> '__init__', '__new__', '__reduce__', '__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']
> >>> print f.func_code.co_argcount
> 1
> >>>




More information about the Python-list mailing list