File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -545,6 +545,43 @@ New 是真正创建实例对象的方法,所以重写基类的new 方法,以
545
545
```
546
546
547
547
# Python高级
548
+ ## 3 函数
549
+ ## 3.6 手写一个判断时间的装饰器
550
+ ```
551
+ import datetime
552
+
553
+
554
+ class TimeException(Exception):
555
+ def __init__(self, exception_info):
556
+ super().__init__()
557
+ self.info = exception_info
558
+
559
+ def __str__(self):
560
+ return self.info
561
+
562
+
563
+ def timecheck(func):
564
+ def wrapper(*args, **kwargs):
565
+ if datetime.datetime.now().year == 2019:
566
+ func(*args, **kwargs)
567
+ else:
568
+ raise TimeException("函数已过时")
569
+
570
+ return wrapper
571
+
572
+
573
+ @timecheck
574
+ def test(name):
575
+ print("Hello {}, 2019 Happy".format(name))
576
+
577
+
578
+ if __name__ == "__main__":
579
+ test("backbp")
580
+ ```
581
+ ## 3.7 使用Python内置的filter()方法来过滤?
582
+ ```
583
+ [x for x in filter(lambda x: x % 2 == 0, range(10))]
584
+ ```
548
585
## 4设计模式
549
586
## 4.1 对设计模式的理解,简述你了解的设计模式?
550
587
设计模式是经过总结,优化的,对我们经常会碰到的一些编程问题的可重用解决方案。一个设计模式并不像一个类或一个库那样能够直接作用于我们的代码,反之,设计模式更为高级,它是一种必须在特定情形下实现的一种方法模板。
You can’t perform that action at this time.
0 commit comments