Thursday, 5 September 2013

Write before and after decorator

Write before and after decorator

I have following sample code,
def say_hello(f):
def wrap():
print "Hello"
return wrap
def say_bye(f):
def wrap():
print "Bye"
return wrap
@say_hello
@say_bye
def process():
return "Processing"
process()
Output:
Hello
I was expecting output as:
Bye
Hello
Processing
What could be wrong?
How to make decorators those will be called before and after function call?
Means, with above example, Can I have output:
Hello
Processing
Bye

No comments:

Post a Comment