Python3 exec locals - this must be a FAQ

Helmut Jarausch jarausch at
Tue Feb 12 12:46:14 CET 2013


I've tried but didn't find an answer on the net.

The exec function in Python modifies a copy of locals() only.
How can I transfer changes in that local copy to the locals of my function
** without **  knowing the names of these variables.

E.g.  I have a lot of local names.


_locals= locals()
expr=compile(input('statements assigning to some local variables '),
                                                 'user input','exec')

How can I "copy" the new values within _locals to my current locals.

If I knew that  Var1  has changed I could say
Var1 = _locals['Var1'] but what to do in general?

Many thanks for a hint,

More information about the Python-list mailing list