I have this bit of code:
from ast import literal_eval
# evil exec loop
param_dict = literal_eval(sys.argv[1])
for key in param_dict.keys():
if type(param_dict[key]) != str:
exec(key+"={}".format(param_dict[key]))
else:
exec(key+"='{}".format(param_dict[key])+"'")
please don't judge me on my use of exec. A) this code is only for myself, and I trust my input and B) I find constantly referring to the dictionary as opposed to normal variables tedious. That being said, if you know of a better way to do this, I am open to it.
Now to my question. I would like to take this code and put it into a function in a different file, and then only call this function with the dictionary (or the string representing it) as an argument. But when I tried that, the program cannot find the variable names. I am guessing that these variables stay within the scope of the function, which is why they cannot be seen outside of it. Is there a way around this (without using global)?