This question has already been asked, but not exactly like this (I can't use any of the answers): I want to call a function that returns a dictionary, and if this dictionary is not None
, loop on it and use its key + values on an object. NB: this object is from a class and its class can't be modified. Something like:
def check_ok(s):
return {'prop_1': 'x',
'prop_2': 'y'}
def check_and_update(obj, st):
result = check_ok(st)
if result is not None:
for k, v in result.items():
obj.k = v # doesn't work, of course
What is the solution?