**kwds behavior?

Terry Reedy tjreedy at udel.edu
Tue Sep 2 19:44:38 CEST 2003

"Sean Ross" <sross at connectmail.carleton.ca> wrote in message
news:2S25b.841$I_2.211334 at news20.bellglobal.com...
> better if attempting to write to an non-writable dict raised an
> but that is not the current behaviour.

The dict returned by locals(), even within a function, *is* writable

>>> def f():
...   l = locals()
...   l[5] = 6
...   print l
>>> f()
{5: 6}

However, it is only a dict copy of the local namespace, (which in
CPython happens to not be a dict of any sort).

> So, your call to update has no effect
> on the local namespace and, thus, 'x' is not yet defined locally.

So d=locals() can be used for what it is -- a dict initialized from
the local namespace at a particular time, but which is thereafter
independent from the local namespace.

Terry J. Reedy

More information about the Python-list mailing list