python
文章平均质量分 56
dai__liang
这个作者很懒,什么都没留下…
展开
-
Python装饰器(二)
内置的装饰器 property 先看一个例子: class Student(): def __init__(self, age): self.age = age a = Student(18) a.age = 20 这里age属性可以被直接更改,如果我们需要实现age私有化,可以使用如下: class Student(): def __init__(self, age): self.__age = age def getage(self): print(self.__age原创 2021-03-05 16:20:15 · 106 阅读 · 0 评论 -
Python装饰器(一)
为什么需要装饰器 先看两个例子 def one_hello(): print ("hello!") def two_hello(): print ("hello!") if __name__ == '__main__': one_hello() two_hello() 如果我们要调试这两个函数,有时候会要求调用每个方法前都要记录进入函数的名称,可以最原始的方法如下: def one_hello(): print "[DEBUG]: enter one_h原创 2021-03-05 15:23:33 · 109 阅读 · 0 评论