How to get method parameter names?

Take a look at the inspect module – this will do the inspection of the various code object properties for you. >>> inspect.getfullargspec(a_method) ([‘arg1’, ‘arg2’], None, None, None) The other results are the name of the *args and **kwargs variables, and the defaults provided. ie. >>> def foo(a, b, c=4, *arglist, **keywords): pass >>> inspect.getfullargspec(foo) … Read more

How to get the caller’s method name in the called method?

inspect.getframeinfo and other related functions in inspect can help: >>> import inspect >>> def f1(): f2() … >>> def f2(): … curframe = inspect.currentframe() … calframe = inspect.getouterframes(curframe, 2) … print(‘caller name:’, calframe[1][3]) … >>> f1() caller name: f1 this introspection is intended to help debugging and development; it’s not advisable to rely on it … Read more

What does the slash mean in help() output?

It signifies the end of the positional only parameters, parameters you cannot use as keyword parameters. Before Python 3.8, such parameters could only be specified in the C API. It means the key argument to __contains__ can only be passed in by position (range(5).__contains__(3)), not as a keyword argument (range(5).__contains__(key=3)), something you can do with … Read more