python decorator with arguments of decorated function

前端 未结 3 1576
小鲜肉
小鲜肉 2021-01-20 15:19

When I wrap a function with @, how do I make the wrapper function look & feel exactly like the wrapped function? help(function) in particular.<

3条回答
  •  醉话见心
    2021-01-20 15:57

    I think the other answers are preferable, but if for some reason you don't want to use an external module, you could always alter your decorator like so:

    def wraps(f):
      def call(*args, **kw):
        print('in', f, args, kw)
        return f(*args, **kw)
    call.__name__ = f.__name__
    call.__doc__ = f.__doc__
    return call
    

提交回复
热议问题