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


Groups > comp.lang.python > #29603 > unrolled thread

Re: [Q] How to exec code object with local variables specified?

Started byPeter Otten <__peter__@web.de>
First post2012-09-21 09:42 +0200
Last post2012-09-21 09:42 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [Q] How to exec code object with local variables specified? Peter Otten <__peter__@web.de> - 2012-09-21 09:42 +0200

#29603 — Re: [Q] How to exec code object with local variables specified?

FromPeter Otten <__peter__@web.de>
Date2012-09-21 09:42 +0200
SubjectRe: [Q] How to exec code object with local variables specified?
Message-ID<mailman.989.1348213304.27098.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web