TableOfContents

Include(ZPyUGnav)

优雅型修饰

decorator的另一种写法 {{{from leopay <[email protected]> reply-to [email protected], to [email protected], date Wed, Apr 16, 2008 at 11:43 PM subject [CPyUG:47631] decorator的另一种写法 }}}

一般decorator都是写一个嵌套函数,

   1 def A(func):
   2     def new_func(*args, **argkw):
   3         #做一些额外的工作
   4         return func(*args, **argkw) #调用原函数继续进行处理
   5     return new_func
   6 @A
   7 def f(args):pass

其实也有另外一种"优雅"点的写法:

   1 def A(func, *args, **argkw):
   2     #做一些额外的工作
   3     return func(*args, **argkw) #调用原函数继续进行处理
   4 
   5 @A.__get__
   6 def f(args):pass    


反馈

创建 by -- ZoomQuiet [DateTime(2008-04-17T08:24:11Z)]

PageComment2

[:/PageCommentData:PageCommentData]