del

Hans Nowak wurmy at earthlink.net
Fri Feb 14 19:09:18 EST 2003


Daniel Silva wrote:

> On Fri, 14 Feb 2003, Hans Nowak wrote:
> 
>>It's not uncommon to delete a name when you don't need it anymore.  Especially
>>in modules.  For example, in site.py:
>>
>>for m in sys.modules.values():
>>     if hasattr(m, "__file__") and m.__file__:
>>         m.__file__ = os.path.abspath(m.__file__)
>>del m
>>
>>m is only a temporary variable that isn't necessary anymore after it has done
>>its job.  Leaving it around makes it available when site.py is imported:
> 
> m should be out of scope outside the for loop, right?

Loops don't have a scope of their own.  The variable stays around when the loop 
is done.

>>>>for i in [1,2,3]:
>>>
> ...     pass
> ...
> 
>>>>i
>>>
> 3
> 
> This seems more like a bug in 2.2.  Didn't someone say that would be fixed
> in 2.3?

Not likely.

> hmm.. hope those are all container removals...

Most of them, but not all of them.

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/
Kaa:: http://www.awaretek.com/nowak/kaa.html
Soon: http://zephyrfalcon.org/





More information about the Python-list mailing list