List comprehension vs filter()

Ian Kelly ian.g.kelly at gmail.com
Wed Apr 20 14:35:29 EDT 2011


On Wed, Apr 20, 2011 at 12:03 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Thu, Apr 21, 2011 at 12:44 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> So, the question for the OP:  Is this file being run with execfile?
>>
>
> Not execfile per se; the code is fetched from the database and then
> executed with:
>
> PyObject *v=PyRun_StringFlags(code,Py_file_input,py_globals,locals,0);
>
> Is Py_file_input the problem?

Not specifically.  The problem is that you're execing the code, and
the locals and globals are two different namespaces, as Peter
suggested.  Since the locals namespace is not associated with a
function, the compiler evidently doesn't generate closures for it, and
thus the lambda (which has its own locals namespace) can't see it.

That's my take, anyway.  Somebody else may have better insight than me.

Cheers,
Ian



More information about the Python-list mailing list