Skip to content

Commit 13e084a

Browse files
committed
增加Python高级中的3.6和3.7
1 parent 0ffca44 commit 13e084a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,43 @@ New 是真正创建实例对象的方法,所以重写基类的new 方法,以
545545
```
546546

547547
# 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+
```
548585
## 4设计模式
549586
## 4.1 对设计模式的理解,简述你了解的设计模式?
550587
设计模式是经过总结,优化的,对我们经常会碰到的一些编程问题的可重用解决方案。一个设计模式并不像一个类或一个库那样能够直接作用于我们的代码,反之,设计模式更为高级,它是一种必须在特定情形下实现的一种方法模板。

0 commit comments

Comments
 (0)