PyEval_GetLocals and unreferenced variables

Chris Angelico rosuav at gmail.com
Wed Nov 26 05:35:12 EST 2014


On Wed, Nov 26, 2014 at 9:22 PM, Kasper Peeters <kasper at phi-sci.com> wrote:
> That is, I want
> to do:
>
>   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 pull 'q' into the local scope
> from within my C code?

Wouldn't this be a little surprising? Why not simply pass q as a parameter?

ChrisA



More information about the Python-list mailing list