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


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

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

Started byMakoto Kuwata <kwa@kuwata-lab.com>
First post2012-09-20 20:27 +0900
Last post2012-09-21 13:20 -0700
Articles 3 — 2 participants

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


Contents

  [Q] How to exec code object with local variables specified? Makoto Kuwata <kwa@kuwata-lab.com> - 2012-09-20 20:27 +0900
    Re: [Q] How to exec code object with local variables specified? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-21 13:20 -0700
    Re: [Q] How to exec code object with local variables specified? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-21 13:20 -0700

#29548 — [Q] How to exec code object with local variables specified?

FromMakoto Kuwata <kwa@kuwata-lab.com>
Date2012-09-20 20:27 +0900
Subject[Q] How to exec code object with local variables specified?
Message-ID<mailman.955.1348140460.27098.python-list@python.org>
Hi,

Is it possible to run code object with local variables specified?
I'm trying the following code but not work:

    def fn():
       x = 1
       y = 2
    localvars = {'x': 0}
    exec(fn.func_code, globals(), localvars)
    print(localvars)
    ## what I expected is: {'x': 1, 'y': 2}
    ## but actual is:      {'x': 0}

Python: 2.7.3
OS: MacOS X

--
regards,
makoto kuwata

[toc] | [next] | [standalone]


#29674

From88888 Dihedral <dihedral88888@googlemail.com>
Date2012-09-21 13:20 -0700
Message-ID<a1f8e223-bc36-4887-9264-7779fea1ffab@googlegroups.com>
In reply to#29548
Makoto Kuwata於 2012年9月20日星期四UTC+8下午7時27分40秒寫道:
> Hi,
> 
> 
> 
> Is it possible to run code object with local variables specified?
> 
> I'm trying the following code but not work:
> 
> 
> 
>     def fn():
> 
>        x = 1
> 
>        y = 2
> 
>     localvars = {'x': 0}
> 
>     exec(fn.func_code, globals(), localvars)
> 
>     print(localvars)
> 
>     ## what I expected is: {'x': 1, 'y': 2}
> 
>     ## but actual is:      {'x': 0}
> 
> 
> 
> Python: 2.7.3
> 
> OS: MacOS X
> 
> 
> 
> --
> 
> regards,
> 
> makoto kuwata

Do you plan to write an IDE for python scrits ?

I have seen a lot abusiosns of spawns or pipes of mutlti-processes, 
and now the exec part again.

I think the sources of Doctor Python and IDLE were available 
years ago for showing off python's capabilities in developing an IDE.

[toc] | [prev] | [next] | [standalone]


#29675

From88888 Dihedral <dihedral88888@googlemail.com>
Date2012-09-21 13:20 -0700
Message-ID<mailman.1035.1348258840.27098.python-list@python.org>
In reply to#29548
Makoto Kuwata於 2012年9月20日星期四UTC+8下午7時27分40秒寫道:
> Hi,
> 
> 
> 
> Is it possible to run code object with local variables specified?
> 
> I'm trying the following code but not work:
> 
> 
> 
>     def fn():
> 
>        x = 1
> 
>        y = 2
> 
>     localvars = {'x': 0}
> 
>     exec(fn.func_code, globals(), localvars)
> 
>     print(localvars)
> 
>     ## what I expected is: {'x': 1, 'y': 2}
> 
>     ## but actual is:      {'x': 0}
> 
> 
> 
> Python: 2.7.3
> 
> OS: MacOS X
> 
> 
> 
> --
> 
> regards,
> 
> makoto kuwata

Do you plan to write an IDE for python scrits ?

I have seen a lot abusiosns of spawns or pipes of mutlti-processes, 
and now the exec part again.

I think the sources of Doctor Python and IDLE were available 
years ago for showing off python's capabilities in developing an IDE.

[toc] | [prev] | [standalone]


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


csiph-web