Perhaps the easiest way to find a signature for a function is help(function) :
>>> def function(arg1, arg2="foo", *args, **kwargs): pass >>> help(function) Help on function function in module __main__: function(arg1, arg2='foo', *args, **kwargs)
In addition, in Python 3, a method was added to the inspect module, called signature , that is designed to represent the signature of the called object and its reverse annotation :
>>> from inspect import signature >>> def foo(a, *, b:int, **kwargs): ... pass >>> sig = signature(foo) >>> str(sig) '(a, *, b:int, **kwargs)' >>> str(sig.parameters['b']) 'b:int' >>> sig.parameters['b'].annotation <class 'int'>
Stefan van den Akker Aug 01 '14 at 9:17 a.m. 2014-08-01 09:17
source share