Created
March 9, 2018 14:53
-
-
Save norbinsh/75b4afd206815f3cfd0df7c4839f74b6 to your computer and use it in GitHub Desktop.
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
""" | |
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