exec src in {}, {} strangeness
Stefan Seefeld
seefeld at sympatico.ca
Mon Mar 21 12:00:59 EST 2005
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... there are
> no "locals" there, so locals() just maps through to globals().
> (Probably this applies to all code at the module level,
> as oppsed to code inside any callable, but I haven't
> verified... you can easily enough.)
>
> Does this information invalidate your bug report?
No, but that's possibly only because I don't (yet) understand
the implications of what you are saying.
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 = Foo' the interpreter only looked in 'b', not 'a'.
Thanks,
Stefan
More information about the Python-list
mailing list