![]() | 1 crayygy 2017-07-20 11:08:51 +08:00 via iPhone ![]() 作为一个靠缩进的语言,你这样子发别人很难看的清楚,建议发个 gist,或者至少也要注意一下排版 |
2 NoAnyLove 2017-07-20 13:25:45 +08:00 我纯粹是被标题吸引进来的,就想看看什么大婶这么厉害,还会编程,中关村扫地大婶? 另外,没缩进的 Python 代码我根本读不懂。。。。。。 |
![]() | 3 Sapp 2017-07-20 13:29:58 +08:00 ![]() 那些说 python 缩进设计好的人呢?来来来,你来读。 |
4 soratadori 2017-07-20 13:39:00 +08:00 @Sapp 如果这个是个不靠缩进的语言你读不读 |
5 AEANWspPmj3FUhDc 2017-07-20 13:41:07 +08:00 via Android 我是小可爱,不是大婶 |
6 iamsunxin OP @crayygy 抱歉,没注意排版就发了,补一个 gist https://gist.github.com/iamsunxin/b1de234354fafeb91f5fb890e433bd0a |
9 iamsunxin OP @ivlioioilvi 给你抓把糖吧 |
![]() | 10 ClutchBear 2017-07-20 18:07:54 +08:00 |
![]() | 11 ClutchBear 2017-07-20 18:09:53 +08:00 这是典型装饰器啊. 简单理解,就是 @count_time(is_debug) def test2(): pr() print 'test2' 单实际执行的是, def count_time(is_debug): def handle_func(test2): def handle_args(*args, **kwargs): if is_debug: begin = t() test2(*args, **kwargs) print ('args2', 'kwargs2', args, kwargs) logging.debug("[" + func.__name__ + "] -> " + str(t() - begin)) else: func(*args, **kwargs) print ('handle_args', handle_args) print (type(handle_args)) return handle_args return handle_func |
![]() | 12 mdzz 2017-07-20 18:24:24 +08:00 ![]() logging.debug 按代码是输出到了 stderr,print 输出到 stdout 而一般 stdout 是带缓冲的,stderr 不带缓冲立即输出 LZ 可以试试把 stdout 和 stderr 分开输出 python.exe timedeco.py >stdout.txt 2>stderr.txt |