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


Groups > comp.lang.python > #81852

Re: PyEval_GetLocals and unreferenced variables

Date 2014-12-03 11:18 +0000
From Kasper Peeters <kasper@phi-sci.com>
Subject Re: PyEval_GetLocals and unreferenced variables
References <mailman.70.1417604405.15533.python-list@python.org>
Newsgroups comp.lang.python
Message-ID <mailman.16527.1417605559.18130.python-list@python.org> (permalink)

Show all headers | View raw


> 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

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


Thread

Re: PyEval_GetLocals and unreferenced variables Kasper Peeters <kasper@phi-sci.com> - 2014-12-03 11:18 +0000
  Re: PyEval_GetLocals and unreferenced variables Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-12-04 01:28 +1300
    Re: PyEval_GetLocals and unreferenced variables Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-04 08:42 -0700

csiph-web