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


Groups > comp.lang.python > #81852

Re: PyEval_GetLocals and unreferenced variables

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <kasper@phi-sci.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'explicit': 0.07; 'modifying': 0.07; 'nested': 0.07; 'function,': 0.09; 'python': 0.11; 'bytecode': 0.16; 'dict': 0.16; "function's": 0.16; 'kasper': 0.16; 'scope.': 0.16; 'code.': 0.18; 'variable': 0.18; 'thanks.': 0.20; 'rules': 0.22; 'visible': 0.24; 'cheers,': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; "i'm": 0.30; 'gives': 0.31; 'but': 0.35; 'in.': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; "you're": 0.61; 'containing': 0.69
Date Wed, 3 Dec 2014 11:18:40 +0000
From Kasper Peeters <kasper@phi-sci.com>
To python-list@python.org
Subject Re: PyEval_GetLocals and unreferenced variables
In-Reply-To <mailman.70.1417604405.15533.python-list@python.org>
References <mailman.70.1417604405.15533.python-list@python.org>
X-Mailer Claws Mail 3.10.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu)
MIME-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16527.1417605559.18130.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417605559 news.xs4all.nl 2860 [2001:888:2000:d::a6]:53523
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81852

Show key headers only | 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