![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python高级
可问春风丶
这个作者很懒,什么都没留下…
展开
-
高阶装饰器
lru_cache和singledispatchfunctools.wrapsfunctools.wraps 是Python标准库中拿来即用的装饰器之一。虽然这不是这篇文章的重点,但还是举个例子:def clock(func): time0 = time.time() @functools.wraps(func) def clocked(*args, ...原创 2018-08-28 20:35:30 · 134 阅读 · 0 评论 -
Python元类
type()>>> from hello import Hello>>> h = Hello()>>> h.hello()Hello, world.>>> print(type(Hello))<type 'type'>>>> print(type(h))原创 2018-08-28 20:36:58 · 179 阅读 · 0 评论 -
函数自省和偏函数
函数内省函数有很多种属性,而其中的很多种属性也是普通对象所有的。使用dir命令可查看函数的所有属性>>> def foo():... pass... >>> dir(foo)['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaul...原创 2018-08-28 20:37:52 · 502 阅读 · 0 评论