本文實例講述了Python實現對一個函數應用多個裝飾器的方法。分享給大家供大家參考,具體如下:
下面的例子展示了對一個函數應用多個裝飾器,可以加多個斷點,在debug模式下,查看程序的運行軌跡。。。
#!/usr/bin/env python#coding:utf-8def decorator1(func): def wrapper(): print 'hello python 之前' func() return wrapperdef decorator2(func): def wrapper(): func() print 'hello python 之后' return wrapper@decorator1@decorator2def test(): print 'hello python!'test()
運行結果:
hello python 之前hello python!hello python 之后
希望本文所述對大家Python程序設計有所幫助。
新聞熱點
疑難解答