You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
794 B
Python

import time
def timer(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print(f"{func.__name__} took {end_time - start_time:.2f} seconds to execute.")
return result
return wrapper
@timer
def my_data_processing_function():
for i in range(100000000):
pass
def func(message):
def get_message(message):
print('Got a message: {}'.format(message))
return get_message(message)
def func_closure():
def get_message(message):
print('Got a message: {}'.format(message))
return get_message
send_message = func_closure()
if __name__ == '__main__':
my_data_processing_function()
func('hello world')
send_message('hello world')