摘要: 装饰器 最简装饰器 def deco(func): def wrap(*args, **kwargs): return func(*args, **kwargs) return wrap @deco def foo(a, b): return a ** b 原理 对比被装饰前后的 foo.__nam 阅读全文
posted @ 2018-10-08 16:39 gugubeng 阅读(140) 评论(0) 推荐(0)
摘要: 迭代器, 生成器 练习: 说出如下代码的打印结果 >>> def foo(): ... print(111) ... yield 222 ... print(333) ... yield 444 ... print(555) ​ >>> n = foo() >>> next(n) >>> next( 阅读全文
posted @ 2018-10-08 16:36 gugubeng 阅读(189) 评论(0) 推荐(0)
摘要: 1. * 和 ** 的用法 函数定义时接收不定长参数 def foo(*args, **kwargs): pass 参数传递 def foo(x, y, z, a, b): print(x) print(y) print(z) print(a) print(b) lst = [1, 2, 3] di 阅读全文
posted @ 2018-10-08 16:33 gugubeng 阅读(423) 评论(0) 推荐(0)
摘要: PEP8 编码规范, 及开发中的一些惯例和建议 练习: 规范化这段代码 from django.conf import settings from user.models import * import sys, os mod=0xffffffff def foo ( a , b = 123 ): 阅读全文
posted @ 2018-10-08 16:31 gugubeng 阅读(213) 评论(0) 推荐(0)