Mick Krippendorf wrote:
<snip>
Yes, and, uh, yes. "locals()['foo'] = bar" works in that it does the
same thing as "foo = bar". So why don't you write that instead?
Mick.
I wouldn't expect it to do the same thing at all, and it doesn't, at
least not in Python 2.6.2. It may store the "bar" somewhere, but not in
anything resembling a local variable.
bar = 42
def mytestfunc():
stuff = 9
locals()['stuff'] = bar
print locals()['stuff']
print stuff
mytestfunc()
prints 9, twice. No sign of the 42 value.
DaveA
--
http://mail.python.org/mailman/listinfo/python-list