Discuss / Python / 有 *args & **kw 就好玩多了呢。。

有 *args & **kw 就好玩多了呢。。

Topic source

瀛匀

#1 Created at ... [Delete] [Delete and Lock User]
import functools

def log(*argu):
   def decorator(func):
      @functools.wraps(func)
      def wrapper(*args, **kw):
         print 'begin call'
         print '%s:' % func.__name__,
         for i in argu:
            print i,
         print '\nend call'
      return wrapper
   return decorator

#@log('Rachel', 'Monica', 'Phoebe')
@log()
def friends():
   pass


friends()

结果:

begin call
friends: Rachel Monica Phoebe 
end call

xjt_matlab

#2 Created at ... [Delete] [Delete and Lock User]

是不是被装饰函数都带参数,只是参数为不为空


  • 1

Reply