Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'subject:code': 0.07; 'subject:How': 0.09; 'expense': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'suggest': 0.11; '2",': 0.16; 'bytecode': 0.16; 'globals(),': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'subject:object': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'subject:] ': 0.19; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.28; 'function': 0.30; 'code': 0.31; 'to:addr :python-list': 0.33; 'faster': 0.35; 'pm,': 0.35; 'subject:?': 0.35; "won't": 0.35; 'there': 0.35; 'received:org': 0.36; 'subject:with': 0.36; 'uses': 0.37; 'object': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'between': 0.63; 'different': 0.63; '20,': 0.65; 'otten': 0.84; 'approach.': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: [Q] How to exec code object with local variables specified? Date: Fri, 21 Sep 2012 09:42:32 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084b03d.dip.t-dialin.net User-Agent: KNode/4.7.3 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348213304 news.xs4all.nl 6933 [2001:888:2000:d::a6]:37720 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29603 Makoto Kuwata wrote: > On Thu, Sep 20, 2012 at 10:15 PM, Peter Otten <__peter__@web.de> wrote: >> >>>>> loc = {} >>>>> exec("x = 1; y = 2", globals(), loc) >>>>> loc >> {'y': 2, 'x': 1} >> >> However, this won't work with the code object taken from a function which >> uses a different a bytecode (STORE_FAST instead of STORE_NAME): >> > > Is there any way to use STORE_FAST instead of STORE_NAME? > > exec("string", ...) is not a solution for me. Can you describe your use-case? Perhaps we can suggest an alternative approach. > # What is different between fn.func_code and compile("string")? func_code has faster bytecode at the expense of flexibility.