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: 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 To: python-list@python.org Subject: Re: PyEval_GetLocals and unreferenced variables In-Reply-To: References: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 > 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