Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81561

Re: PyEval_GetLocals and unreferenced variables

Date 2014-11-26 11:40 +0000
From Kasper Peeters <kasper@phi-sci.com>
Subject Re: PyEval_GetLocals and unreferenced variables
References <20141126102257.141b108f@klug> <CAPTjJmov9s=_0yVSOYSRqoCoy69vyXCKvUpScirjBQDp28Sd4A@mail.gmail.com> <20141126104628.78ed4022@klug> <CAPTjJmpsYodoWMUh=BEpH+iEu14qfznSVrTzrxr0+Yad9SDwjQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.16319.1417002046.18130.python-list@python.org> (permalink)

Show all headers | View raw


> 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 Python compiler is not aware of it though (I could ask my question
purely in Python: how do I check in the scope of fun2 whether 'q' is
available in the outer scope without actually using it).

> I wonder, would a 'nonlocal q' declaration inside fun2 affect things
> any?

Yes, that pulls in 'q', but I would like to do that 'nonlocal q' on the
C side. If I have to write 'nonlocal q' inside fun2 then I can also
pull in 'q' using any other reference to 'q'.

> Otherwise, maybe there's some completely different way to transfer
> information around. Using locals in this way seems fraught with peril.

There might very well be...

Cheers,
Kasper
 

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: PyEval_GetLocals and unreferenced variables Kasper Peeters <kasper@phi-sci.com> - 2014-11-26 11:40 +0000

csiph-web