I would like to define a dictionary with a name that changes dynamically. For example:
Dictname = 'Forrest'
Forrest = {}
The parameter Dictname is received from a textfile, the value forrest will be different every time the script runs
I would like to define a dictionary with a name that changes dynamically. For example:
Dictname = 'Forrest'
Forrest = {}
The parameter Dictname is received from a textfile, the value forrest will be different every time the script runs
Not sure if I read the requirement correctly but here is something to try. I edited the answer after seeing the globals() comment.
Answer 1 is my original answer. However the next answer, answer 2, is more straightforward but is not significantly different from what has already been suggested in comments.
Answer 1.
Dictionary = 'forrest'
exec('%s={}'%Dictionary)
exec('%s[\'mykey\']=123456'%Dictionary)
print(forrest)
Answer 2.
Dictionary = 'forrest'
globals()[Dictionary]={}
globals()[Dictionary]['Mykey']=123456
print(globals()[Dictionary])