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

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


"Manus Hand" <manus at bullfrog-tech.com> wrote in message
news:3D6E82E3.866CBA49 at bullfrog-tech.com...
> 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
post
> at the start of this thread.  However, I soon realized that this line
worked
> 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
a
> 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):
"""
locals()
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.
"""

regards
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                        pydish.holdenweb.com/pwp/
Previous .sig file retired to                    www.homeforoldsigs.com
-----------------------------------------------------------------------






More information about the Python-list mailing list