#! /usr/bin/env python # coding=utf-8 from time import time def logged(when): def log(f,*args,**kargs): print("called: function:%s,args:%r,kargs:%r"%(f,args,kargs)) def pre_logged(f): def wrapper(*args,**kargs): log(f,*args,**kargs) return f(*args,**kargs) def post_logged(f): def wrapped(*args,**kargs): now=time() try: return f(*args,**kargs) finally: log(f,*args,**kargs) print("time delta:%s"%(time()-now)) return wrapped try: #從這裡開始呼叫 return{"pre":pre_logged,"post":post_logged}[when] except Exception as e: print(e) @logged("post") def hello(name): print("hello",name) @logged("post") def test(a,b=1): print(a+b) hello("world") test(1,2)
用python 裝飾器打log
相關文章
- python裝飾器2:類裝飾器Python
- Python 裝飾器你也會用Python
- python裝飾器decorator的應用Python
- Python 裝飾器Python
- Python裝飾器Python
- [Python小記] 裝飾器怎麼用 ?Python
- 1.5.3 Python裝飾器Python
- Python 裝飾器(一)Python
- python的裝飾器Python
- Python 裝飾器原理Python
- Python裝飾器模式Python模式
- Python深入05 裝飾器Python
- python 之裝飾器(decorator)Python
- Python中的裝飾器Python
- Python裝飾器詳解Python
- python裝飾器入門探究Python
- python 裝飾器 part2Python
- day11(python)裝飾器Python
- python中裝飾器的原理Python
- Python裝飾器高階用法Python
- python 裝飾器小白學習Python
- 【python】閉包與裝飾器Python
- Python裝飾器的前世今生Python
- python的裝飾器@的用法Python
- Python深入分享之裝飾器Python
- Python 語法之裝飾器Python
- Python3 裝飾器解析Python
- Python閉包與裝飾器Python
- Python之函式裝飾器Python函式
- Python 裝飾器簡單示例Python
- python裝飾器有哪些作用Python
- python裝飾器是什麼Python
- 粗淺聊聊Python裝飾器Python
- Python迭代器&生成器&裝飾器Python
- python幾種裝飾器的用法Python
- Python學習筆記 - 裝飾器Python筆記
- Python:從閉包到裝飾器Python
- python中的裝飾器介紹Python
- python3 裝飾器全解Python