Feb-15-2020, 04:08 PM
I need to create local variables whose names come from an externally specified string. I tried
The vars() doc says
"Without an argument, vars() acts like locals(). Note, the locals dictionary is only useful for reads since updates to the locals dictionary are ignored."
If I do the same thing with globals
Why the restriction with vars and local? And is there a way to create a local variable?
vars()[varname] = somevalueThis code ran without an error, but it did not create the variable whose name was given in varname.
The vars() doc says
"Without an argument, vars() acts like locals(). Note, the locals dictionary is only useful for reads since updates to the locals dictionary are ignored."
If I do the same thing with globals
globals()[varname] = somevaluethe variable is created but is, of course, global.
Why the restriction with vars and local? And is there a way to create a local variable?