当我用以下内容包装函数时@
,如何使包装函数看起来和感觉与包装函数完全相同?help(function)
尤其。
一些代码:
>>> def wraps(f):
def call(*args, **kw):
print('in', f, args, kw) # example code. I need to transfer the arguments to another process and pickle them.
return f(*args, **kw)
return call
>>> def g():pass
>>> @wraps
def f(a, b = 1, g = g, *args, **kw):
pass
>>> help(f)
Help on function call in module __main__:
call(*args, **kw) # this line bothers me. It should look different, look below
>>> def f(a, b = 1, g = g, *args, **kw):
pass
>>> help(f)
Help on function f in module __main__:
f(a, b=1, g=<function g at 0x02EE14B0>, *args, **kw) # help(f) should look like this.
动机:当我键入时,当弹出帮助窗口时看到参数也很好f(
*扑通*我明白了(a, b = 1, g = g, *args, **kw)
。 (在本例中是在 IDLE Python Shell 中)
我看了一下inspect
模块帮助我进行良好的格式化。问题仍然存在:我该如何用参数来做到这一点..
默认可变参数传递如下def f(d = {}):
不需要工作,因为我将参数转移到另一个进程,并且身份无论如何都会丢失。