Skip to content

Instantly share code, notes, and snippets.

@norbinsh
Created March 9, 2018 14:53
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 norbinsh/75b4afd206815f3cfd0df7c4839f74b6 to your computer and use it in GitHub Desktop.
Save norbinsh/75b4afd206815f3cfd0df7c4839f74b6 to your computer and use it in GitHub Desktop.
"""
Playing around with decorators.
"""
__author__ = 'Shay Elmualem'
import time
import string
from threading import Thread
def calc_func_runtime(func):
def wrapper():
start = time.time()
func()
end = time.time()
print(f'Time it took for {func} to finish execution: {end - start}')
return wrapper
@calc_func_runtime
def sleep_please():
time.sleep(3)
@calc_func_runtime
def sleep_longer():
time.sleep(5)
def elementp(func):
def wrapper():
return '<p>' + func() + '</p>'
return wrapper
def elementbody(func):
def wrapper():
return '<body>' + func() + '</body>'
return wrapper
@elementbody
@elementp
def generate_letters():
return string.ascii_uppercase
print(generate_letters())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment