[Q] How to exec code object with local variables specified?
88888 Dihedral
dihedral88888 at googlemail.com
Fri Sep 21 16:20:31 EDT 2012
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.
More information about the Python-list
mailing list