I want to use a bunch of local variables defined in a function, outside of the function. So I am passing x=locals() in the return value.
How can I load all the variables defined in that dictionary into the namespace outside the function, so that instead of accessing the value using x['variable'], I could simply use variable.
Consider the
Bunchalternative:so if you have a dictionary
dand want to access (read) its values with the syntaxx.fooinstead of the clumsierd['foo'], just dothis works both inside and outside functions — and it’s enormously cleaner and safer than injecting
dintoglobals()! Remember the last line from the Zen of Python…: