码迷,mamicode.com
首页 > 编程语言 > 详细

python中装饰器装饰类中的方法

时间:2017-10-07 19:44:54      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:creat   each   init   span   pytho   ret   .class   color   course   

 1 ####在装饰器中加入self参数即可
 2 def w_f(f):
 3     def wrapper(self, *args, **kwargs):
 4         f(self, *args, **kwargs)
 5         # print(args[1])
 6     return wrapper
 7 class school:
 8     def __init__(self,name):
 9         self.name = name
10     @w_f
11     def create_class(self):
12         self.class_num = class_num
13         self.course = course
14 
15 class teacher:
16     def __init__(self,name,age):
17         self.name = name
18         self.age = age
19 
20 class course:
21     def __init__(self,name,teacher):
22         self.name = name
23         self.teacher = teacher

 

python中装饰器装饰类中的方法

标签:creat   each   init   span   pytho   ret   .class   color   course   

原文地址:http://www.cnblogs.com/whigo/p/7635412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!