I'm working on an exercise, I tried to solve it, but no result, I had to look at the solution, in order to have an idea and repeat it, the problem, I am stuck, a little lost.
# Create an @authenticated decorator that only allows the function to run is user1 has 'valid' set to True:
user1 = { 'name': 'Sorna',
'valid': True } #changing this will either run or not run the message_friends function.
Solution :
def authenticated(fn):
def wrapper(*args, **kwargs):
if args[0]['valid']:
return fn(*args, **kwargs)
return wrapper
@authenticated
def message_friends(user):
print('message has been sent')
message_friends(user1)
I really don't get this part :
if args[0]['valid']:
My question is if user1 = dict
, why can't i just use **kwards
so i can just check if the value is True by calling only [valid]:
where it comes from the args[0]
?
Help, i'm really stuck with this..