'''Add decorator for each method of a class.'''import functoolsimport threadingclass DecorateClass(object): def decorate(self): for name, fn in self.iter(): if callable(fn): ... Read More
posted @ 2011-12-21 17:01 张云贵 Views(3391) Comments(0) Diggs(0) Edit
这是在Python学习小组上介绍的内容,现学现卖、多练习是好的学习方式。 第一步:最简单的函数,准备附加额外功能 # -*- coding:gbk -*-'''示例1: 最简单的函数,表示调用了两次'''def myfunc(): print("myfunc() called.")myfunc()myfunc()第二步:使用装饰函数在函数执行前和执行后分别附加额外功能# -*- c... Read More
posted @ 2011-12-21 10:30 张云贵 Views(139742) Comments(15) Diggs(47) Edit