I'm trying to assign the values of a nested dictionary to variables named after their key. I found this code on Stackoverflow but it only prints the key and value pair:
def myprint(d):
for k, v in d.items():
if isinstance(v, dict):
myprint(v)
else:
print("{0} : {1}".format(k, v))
I would like it so that for example, if I have the following in my dictionary: {thisIsADummy : 37}
I can somehow create a variable named thisIsADummy
, named after the key, with the value 37
So my input ould be print(thisIsADummy)
and the output would be 37
Please let me know if anybody has any ideas on how to do this as efficiently as possible, because this dictionary has probably over a thousand pairs. Thank you.
EDIT:
Using exec
works well, but I oversimplified in the original post. I need the variable to be a dictionary so when I open multiple files I can append values.