Since it is not safe to change the dict that locals () returns
>>> d={'a':6, 'b':"hello", 'c':set()} >>> exec '\n'.join("%s=%r"%i for i in d.items()) >>> a 6 >>> b 'hello' >>> c set([])
But using exec like this is ugly. You must redesign, so you do not need to dynamically add to the local namespace
Edit: See Mike on how to use reprint in comments.
>>> d={'a':6, 'b':"hello", 'c':set()} >>> exec '\n'.join("%s=d['%s']"%(k,k) for k in d) >>> id(d['c']) 3079176684L >>> id(c) 3079176684L
John la rooy
source share