Given a function object, how can I get its signature? For example, for:
def myMethod(firt, second, third='something'): pass
I would like to get "myMethod(firt, second, third='something')".
"myMethod(firt, second, third='something')"
import inspect def foo(a, b, x='blah'): pass print(inspect.getargspec(foo)) # ArgSpec(args=['a', 'b', 'x'], varargs=None, keywords=None, defaults=('blah',))
However, note that inspect.getargspec() is deprecated since Python 3.0.
inspect.getargspec()
Python 3.0--3.4 recommends inspect.getfullargspec().
inspect.getfullargspec()
Python 3.5+ recommends inspect.signature().
inspect.signature()
1.4m articles
1.4m replys
5 comments
57.0k users