Created
September 30, 2013 02:44
-
-
Save zxkletters/6758791 to your computer and use it in GitHub Desktop.
demo of decorator in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Created on 2013-4-8 | |
@author: xiaoke.zhangxk | |
""" | |
def blue_box(func): | |
def wrapped(): | |
print "~~ blue ~~~" | |
func() | |
print "~~ blue ~~" | |
return wrapped | |
def red_box(func): | |
def wrapped(): | |
print "** red **" | |
func() | |
print "** red **" | |
return wrapped | |
def box(): | |
print " i am a box." | |
box() | |
print "-----------------" | |
decorated = red_box(blue_box(box)) | |
decorated() | |
print "-----------------" | |
@blue_box | |
@red_box | |
def new_box(): | |
print "i am another box." | |
new_box() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment