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

Manus Hand manus at
Thu Aug 29 22:24:03 CEST 2002

Another follow-up....

It seems that all my code of the form:
still DOES work fine under 2.2.  (Yay!  Whew!)

The one thing that STOPPED working reliably is this:

locals()[varName] = someValue

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
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).

I then figured the issue still had to do with scope nests, although I did think

it pretty inconsistent and screwy that the same code would work fine at global
scope but not when you stuck it into a function.  But then....

I wrote a simple test function:

def func(varDict):
    for var in varDict:                # or these two lines could
        locals()[var] = varDict[var]   # be locals().update(varDict)
    print locals()

Works fine.

When this same code snippet is in the handler() function for mod_python,
like this:

def handler(req):
    for var in util.FieldStorage(req).list:
        locals()[] = urllib.unquote(var.value)
    print locals()
    return apache.OK

def runAnother(form):
    for var in form:
        print var, form[var], '<br>'  # <-- yes, it prints them all
        locals()[var] = form[var]
    print locals()  # <--- but this one gets some SUBSET of the variables!!

That is, SOME of them make it and other ones don't.

The assignment doesn't except, but it also doesn't assign!

In short, I had initially thought this was caused by PEP 227; now I am not so


More information about the Python-list mailing list