赞
踩
def df(a, b,c): return a,b,c def get_func_args(func, stripself=False): import inspect from functools import partial, wraps """Return the argument name list of a callable object""" if not callable(func): raise TypeError(f"func must be callable, got '{type(func).__name__}'") args = [] try: sig = inspect.signature(func) except ValueError: return args if isinstance(func, partial): partial_args = func.args partial_kw = func.keywords for name, param in sig.parameters.items(): if param.name in partial_args: continue if partial_kw and param.name in partial_kw: continue args.append(name) else: for name in sig.parameters.keys(): args.append(name) if stripself and args and args[0] == "self": args = args[1:] return args
返回结果:
[‘a’, ‘b’, ‘c’]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。