Ask coding questions

← Back to all posts
i didn't get this question can you please explain this ques?
shivam14

Create an @authenticated decorator that only allows the function to run is user1 has 'valid' set to True:

user1 = {
'name': 'Sorna',
'valid': True
}

def authenticated(fn):
def wrapper(args, **kwargs):
if args[0]:
return fn(
args, **kwargs)
return wrapper

@authenticated
def message_friends(user):
print('message has been sent')

message_friends(user1)

Voters
khushbusuryawan
shivam14
Comments
hotnewtop
[deleted]

This page has all the information you need to solve the problem: https://www.programiz.com/python-programming/decorator