Re: interactive execution

2005-02-09 Thread Jeff Shannon
Jive Dadson wrote: Yeah. I got it. exec "foo = 555" in globals(), locals() does the trick. You can do it with your own dicts, too -- but they must already exist, exec doesn't create them out of nowhere. >>> myglobals = {'a':2, 'b':5} >>> mylocals = {'c': 3} >>> exec "d = a * b + c" in myglobals,

Re: interactive execution

2005-02-08 Thread Jive Dadson
Yeah. I got it. exec "foo = 555" in globals(), locals() does the trick. -- http://mail.python.org/mailman/listinfo/python-list

Re: interactive execution

2005-02-08 Thread Jive Dadson
Jeff Shannon wrote: > > Jive Dadson wrote: > > > How does one execute arbitrary text as code within a module's context? > > > > I've got some code that compiles some text and then executes it. When > > the string is "print 'Hello'", it prints "Hello". I get no exception > > when I compile and

Re: interactive execution

2005-02-08 Thread George Yoshida
Jive Dadson wrote: I've got some code that compiles some text and then executes it. When the string is "print 'Hello'", it prints "Hello". I get no exception when I compile and execute "foo = 555". If I then compile and exec "print foo", I get a name error. The variable foo is undefined. My assu

Re: interactive execution

2005-02-08 Thread Jeff Shannon
Jive Dadson wrote: How does one execute arbitrary text as code within a module's context? I've got some code that compiles some text and then executes it. When the string is "print 'Hello'", it prints "Hello". I get no exception when I compile and execute "foo = 555". If I then compile and exec

interactive execution

2005-02-08 Thread Jive Dadson
How does one execute arbitrary text as code within a module's context? I've got some code that compiles some text and then executes it. When the string is "print 'Hello'", it prints "Hello". I get no exception when I compile and execute "foo = 555". If I then compile and exec "print foo", I get