Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'exec': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'globals': 0.09; 'message- id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'am,': 0.12; 'assignments,': 0.16; 'processed.': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'runs,': 0.16; 'cc:addr:python- list': 0.16; 'wrote:': 0.16; 'issue,': 0.18; 'cc:no real name:2**0': 0.20; '(like': 0.21; 'header:In-Reply-To:1': 0.22; 'tue,': 0.23; 'etc,': 0.23; 'aug': 0.24; 'code': 0.25; 'string': 0.26; 'function': 0.27; 'bit': 0.28; 'problem': 0.28; 'environment': 0.29; "won't": 0.29; 'cc:addr:python.org': 0.30; 'definition': 0.30; 'does': 0.32; 'actually': 0.33; 'too': 0.33; 'there': 0.33; 'header:User-Agent:1': 0.34; '(as': 0.34; 'things': 0.34; 'cc:2**1': 0.36; 'subject:: ': 0.39; 'user': 0.39; 'empty': 0.39; 'subject:from': 0.40; 'more': 0.60; 'your': 0.61; 'received:websitewelcome.com': 0.64; 'ready': 0.65; 'received:184': 0.67; 'want,': 0.71; 'soon': 0.72; 'spoke': 0.73; '30,': 0.74; 'locals': 0.84; 'mind:': 0.84; 'received:67.18.82': 0.84; 'received:gateway15.websitewelcome.com': 0.84; 'subject:value': 0.84; 'supplying': 0.84; 'items,': 0.91; 'subject:better': 0.93 Date: Tue, 30 Aug 2011 11:19:52 -0700 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: Jack Trades Subject: Re: Returning a value from exec or a better solution References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:4711 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== Cc: python-list@python.org, Rob Williscroft X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314727377 news.xs4all.nl 2452 [2001:888:2000:d::a6]:47423 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12442 Jack Trades wrote: > On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: >> If an impementation (as you say up thread) can populate globals >> or locals with whatever they want, then how do you know that last >> item added was the function definition the user supplied ? Because the implementation will add things before the exec is processed. Then when the exec actually runs, any assignments, definitions, etc, from the user supplied string will be added. > I spoke a bit too soon with the "works flawlessly" post. In addition to > your issue, there is also the problem that supplying an empty > environment does not allow the user to call necessary functions (like > scheme_eval). So, just like an implementation, add the functions to the CapturingDict before the exec. One thing to keep in mind: the CapturingDict only remembers the *last* thing created/assigned... so if the user code has more than one def/class/name assignment, you won't have ready access to the first items, only that last one. ~Ethan~