I have a question about PyEval_GetLocals(). The normal behaviour of
PyEval_GetLocals(), and in fact of the locals() function in Python
itself, is to return a list which includes only those variables which
are actually referenced in the local scope. Example:
def fun():
q=3
def fun2():
> > def fun():
> > q=3
> > def fun2():
> > cfun()
> > fun2()
> >
> > fun()
> >
> > and access 'q' inside the C-function cfun(). If I simply let it call
> > PyEval_GetLocals, then the result will again not contain "q". Is
> > there any way in which I can convince python to
> To be honest, that's just made it even more weird :) You're creating
> something in a local namespace that the Python compiler isn't aware
> of.
Yes, I agree that retrieving the locals with PyEval_GetLocals and then
sticking something in there on the C side is weird. I wouldn't say that
the Pyth
> > def fun():
> >cfun_that_creates_q_in_local_scope()
> >def fun2():
> >cfun_that_wants_to_see_if_q_is_available()
> >
> > So the Python side actually doesn't see 'q' directly at all.
>
> I think you will need to elaborate.
Ok, here goes (and thanks for listening)
> 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