execfile question

Steven Majewski sdm7g at Virginia.EDU
Tue Feb 19 16:48:39 EST 2002


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
>>>



On Tue, 19 Feb 2002, Steven Majewski wrote:

> On Tue, 19 Feb 2002, Kerim Borchaev wrote:
> > And can you explain who holds a reference on C instance in my example
> > when 'execfile' completes?
>
> 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.
> >>> print execfile.__doc__
> execfile(filename[, globals[, locals]])
>
> Read and execute a Python script from a file.
> The globals and locals are dictionaries, defaulting to the current
> globals and locals.  If only globals is given, locals defaults to it.
>
> >>> execfile( 'executable.py' )
> it's me
> init
> >>> dir()
> ['C', '__builtins__', '__doc__', '__name__', 'c']
> >>> del c
> deleted
> >>>





More information about the Python-list mailing list