Re: exec src in {}, {} strangeness

2005-03-24 Thread Brano Zarnovican
As Greg pointed.. g = {} exec open('t.py').read() in g, g is what you want. But you can write it also this way: exec open('t.py').read() in {} because if you specify only globals, the same dictionary is also used for locals. (locals() is used as a default only if you don't specify globals) OR

Re: exec src in {}, {} strangeness

2005-03-21 Thread Stefan Seefeld
Do Re Mi chel La Si Do wrote: Hi ! Try : exec f in globals(),locals() or exec(f,globals(),locals()) or exec f in globals(),globals() or exec(f,globals(),globals()) Indeed, using 'globals()' and 'locals()' works. However, both report the same underlaying object, which is a bit

Re: exec src in {}, {} strangeness

2005-03-21 Thread Peter Hansen
Stefan Seefeld wrote: Indeed, using 'globals()' and 'locals()' works. However, both report the same underlaying object, which is a bit confusing. (Under what circumstances does 'locals()' return not the same object as 'globals()' ?) When you aren't at the interactive prompt... there are no locals

Re: exec src in {}, {} strangeness

2005-03-21 Thread Stefan Seefeld
Peter Hansen wrote: Stefan Seefeld wrote: Indeed, using 'globals()' and 'locals()' works. However, both report the same underlaying object, which is a bit confusing. (Under what circumstances does 'locals()' return not the same object as 'globals()' ?) When you aren't at the interactive prompt...

Re: exec src in {}, {} strangeness

2005-03-21 Thread Bernhard Herzog
Stefan Seefeld [EMAIL PROTECTED] writes: Is there anything wrong with 'exec source in a, b' where a and b are distinc originally empty dictionaries ? Again, my test code was class Foo: pass class Bar: foo = Foo and it appears as if 'Foo' was added to 'a', but when evaluating 'foo =

Re: exec src in {}, {} strangeness

2005-03-21 Thread Stefan Seefeld
Bernhard Herzog wrote: Stefan Seefeld [EMAIL PROTECTED] writes: Is there anything wrong with 'exec source in a, b' where a and b are distinc originally empty dictionaries ? Again, my test code was class Foo: pass class Bar: foo = Foo and it appears as if 'Foo' was added to 'a', but when

Re: exec src in {}, {} strangeness

2005-03-21 Thread Greg Ewing
Stefan Seefeld wrote: Bernhard Herzog wrote: When foo = Foo is executed, Foo is first looked up in that new locals dictionary. That fails, so it's also looked up in the globals dictionary a. That fails as well because Foo was bound in b. The final lookup in the builtins also fails, and thus you

Re: exec src in {}, {} strangeness

2005-03-20 Thread Do Re Mi chel La Si Do
Hi ! Try : exec f in globals(),locals() or exec(f,globals(),locals()) or exec f in globals(),globals() or exec(f,globals(),globals()) @-salutations Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list