Compare commits

..

2 Commits

Author SHA1 Message Date
fenix 7bfa1bc9da decorator - Py iii <- pre function parameters 2024-02-13 14:30:23 +01:00
fenix 11acf9073d decorator - Py ii pre -pie Decorator 2024-02-13 14:16:17 +01:00
3 changed files with 18 additions and 0 deletions

5
decorators.py Normal file
View File

@ -0,0 +1,5 @@
def do_twice(func):
def wrapper_do_twice():
func()
func()
return wrapper_do_twice

View File

@ -5,6 +5,7 @@ def decorator(func):
print("Something is happening after the function is called.") print("Something is happening after the function is called.")
return wrapper return wrapper
@decorator
def say_whee(): def say_whee():
print("Whee!") print("Whee!")

12
quiet_night.py Normal file
View File

@ -0,0 +1,12 @@
from datetime import datetime
def not_during_the_night(func):
def wrapper():
if 7 <= datetime.now().hour < 22:
func()
else:
pass # Hush, the neighbors are asleep
return wrapper
def say_whee():
print("Whee!")