Execfile() - bug / strange behavior

Carel Fellinger cfelling at iae.nl
Sat Feb 5 00:57:47 CET 2000


Tim Peters <tim_one at email.msn.com> wrote:
> {Amit Patel]
>> I'm trying to understand why execfile(fn) is different from exec
>> open(fn,'r').read().  Here's my program:
>>
>> def timbot():
>>     a = 3
>>     execfile("1.txt")
>>     print a
>>     print locals()
>> timbot()
>>
>>

> You can't actually get the timbot interested in pursuing this, since it
> never uses these things without explicity naming the dicts it wants used as
> execution context.

And how then would it pass on the locals dict in this case? According to
the docs, and a recent explanation on this list, it is not possible to
use something like execfile("1.txt", globals(), locals()), as those are
readonly in case of functions! One of the few dark corners of Python IMHO.
-- 
groetjes, carel



More information about the Python-list mailing list