-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorators.py
More file actions
38 lines (24 loc) · 715 Bytes
/
decorators.py
File metadata and controls
38 lines (24 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
PASSWORD = '12345'
def password_required(func):
def wrapper():
password = input('What is your password? ')
if password == PASSWORD:
return func()
else:
print('The password is incorrect!')
return wrapper
@password_required # Este es nuestro decorador puesto en práctica
def needs_password():
print('The password is correct!')
def upper(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return result.upper()
return wrapper
@upper
def say_my_name(name):
return f'Hello {name}'
if __name__ == '__main__':
name = input('What is your name? ')
print(say_my_name(name))
# needs_password()