python - Is there a way to get function parameter names, including bound-methods excluding `self`? -


i can use inspect.getargspec parameter names of function, including bound methods:

>>> import inspect >>> class c(object): ...     def f(self, a, b): ...             pass ... >>> c = c() >>> inspect.getargspec(c.f) argspec(args=['self', 'a', 'b'], varargs=none, keywords=none, defaults=none) >>> 

however, getargspec includes self in argument list.

is there universal way parameter list of function (and preferably, callable @ all), excluding self if it's method?

edit: please note, solution on both python 2 , 3.

inspect.signature excludes first argument of methods:

>>> inspect import signature >>> list(signature(c.f).parameters) ['a', 'b'] 

you delete first element of args manually:

from inspect import ismethod, getargspec  def exclude_self(func):     args = getargspec(func)     if ismethod(func):         args[0].pop(0)     return args  exclude_self(c.f) # argspec(args=['a', 'b'], ...) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -