摘要: import functools def log(option): def dec(func): def swapper(*arg, **karg): functools.update_wrapper(swapper, func) opt = format(option,"^7") print '[... 阅读全文
posted @ 2016-10-12 17:19 backinfile 阅读(266) 评论(0) 推荐(0) 编辑
摘要: __neg__ python中 __neg__ 方法对应于 符号 - 可见 str 没有__neg__,定义 strnew 好吧,无法再简化了 __iter__ 看看 list 的 __iter__: list_iterator 也是有 __iter__ 的,它返回自己。 python2 迭代调用 阅读全文
posted @ 2016-10-12 15:39 backinfile 阅读(1134) 评论(0) 推荐(0) 编辑
摘要: 哪里出问题了 python 中,使用 global 会将全局变量设为本函数可用。同时,在函数内部访问变量会先本地再全局。 在嵌套函数中,使用 global 会产生不合常理的行为。 上代码: 而在函数 x() 中,没有用 global,此时的b使用本地。所以 print 会打印本地 b 为什么会打印 阅读全文
posted @ 2016-10-12 12:13 backinfile 阅读(3734) 评论(0) 推荐(0) 编辑