execfile question

Bengt Richter bokr at oz.net
Wed Feb 20 06:10:19 CET 2002


On Tue, 19 Feb 2002 16:48:39 -0500 (EST), Steven Majewski <sdm7g at Virginia.EDU> wrote:

>
>PS:
> You can get the behaviour you were expecting if you pass an
>unbound anonymous dict to execfile -- the namespace is
>garbage that's released after execfile returns:
>
>Python 2.2 (#36, Jan 30 2002, 17:50:25)
>[GCC 2.95.2 19991024 (release)] on darwin
>Type "help", "copyright", "credits" or "license" for more information.
>>>> execfile( 'executable.py', {}, {} )
>it's me
>init
>deleted
>>>>
>
Hm. I didn't try it with two {}'s. Why shouldn't one work? Shouldn't it
just use the same for globals and locals?

This "works"
 >>> xdict={}
 >>> execfile('executable.py',xdict)
 it's me
 init
 >>> xdict.clear()
 deleted

but xdict going out of scope doesn't do it
and neither does del xdict. Shouldn't they?

Regards,
Bengt Richter
We should really stay in one thread on this;-/





More information about the Python-list mailing list