Maybe it's a mod_python issue I'm hitting?

Steve Holden sholden at
Thu Sep 5 14:04:21 EDT 2002

"Manus Hand" <manus at> wrote in message
news:3D6E82E3.866CBA49 at
> Another follow-up....
> It seems that all my code of the form:
>     vars(self).update(someDict)
> still DOES work fine under 2.2.  (Yay!  Whew!)
It's not guaranteed to work in later versions, though, I suspect.

> The one thing that STOPPED working reliably is this:
> locals()[varName] = someValue
Don't do that (see below).

> My initial thought was that PEP 227 had made locals() read-only, hence my
> at the start of this thread.  However, I soon realized that this line
> fine
> under 2.2 while it sat at global scope.  The line started failing when I
put it
> into a function (specifically, a handler() function, as part of a port to
> mod_python installation).
Erm, you should NOT treat the locals dictionary as modifiable, whether
running under mod_python or not. The locals() function returns a dictionary
(mapping, anyway), but for a long time now the documentation has said you
should not (necessarily) expect changes to this mapping object to result in
changes to the local name space.

[other confusions]

>From the library manual (section 2.1, Built-In Functions):
Return a dictionary representing the current local symbol table. Warning:
The contents of this dictionary should not be modified; changes may not
affect the values of local variables used by the interpreter.

Steve Holden                        
Python Web Programming              
Previous .sig file retired to          

More information about the Python-list mailing list