PyEval_GetLocals and unreferenced variables

Kasper Peeters kasper at phi-sci.com
Wed Dec 3 06:18:40 EST 2014


> I'm not sure how you think you're adding a local from C
> code. If you're using PyEval_GetLocals(), that only gives
> you a dict containing a *copy* of the locals; modifying
> that dict doesn't change the locals in the function's frame.

That may have been the design plan, but in Python 2.7.6, I definitely
am able to inject locals via PyEval_GetLocals() and have them be visible
both from the C and Python side; see also

http://stackoverflow.com/questions/22276502/create-python-object-in-local-scope-from-within-c

> If the bytecode of the nested function doesn't reference a given
> variable in the outer function, it doesn't get passed in.

Ok, that's good to know because it rules out doing this without having
an explicit reference to the variable in the inner scope. Thanks.

Cheers,
Kasper



More information about the Python-list mailing list