PyEval_GetLocals and unreferenced variables

2014-11-26 Thread Kasper Peeters
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():

Re: PyEval_GetLocals and unreferenced variables

2014-11-26 Thread Kasper Peeters
> > 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

Re: PyEval_GetLocals and unreferenced variables

2014-11-26 Thread Kasper Peeters
> 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

Re: PyEval_GetLocals and unreferenced variables

2014-12-02 Thread Kasper Peeters
> > 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)

Re: PyEval_GetLocals and unreferenced variables

2014-12-03 Thread Kasper Peeters
> 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