Skip to content

Instantly share code, notes, and snippets.

@sujayy1983
Created January 17, 2015 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sujayy1983/89c60142cbeb3ed97ff4 to your computer and use it in GitHub Desktop.
Save sujayy1983/89c60142cbeb3ed97ff4 to your computer and use it in GitHub Desktop.
A simple example of decorator.
"""
@Author: Sujayyendhiren Ramarao
@Description: Decorator design pattern
"""
def logging_decorator( function ):
def func(*args, **kwargs):
print("Entering function" + str(function))
ret = function(*args,**kwargs)
print("Returned from function" + str(function))
return ret
return func
class TestDecorator():
def __init__(self):
self.value = True
@logging_decorator
def get(self):
return self.value
@logging_decorator
def set(self, value):
self.value = value
if __name__ == "__main__":
tDecor = TestDecorator()
print( "GET value: " + str( tDecor.get()) )
print( "SET value: " + str( tDecor.set(False)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment