del

Daniel Silva dsilva at ccs.neu.edu
Fri Feb 14 19:02:36 EST 2003


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?

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

> > More precisely, how many programs would be broken if a python
> > compiler did not implement it?
>
> Lots of them.  Let's see if del is used in the standard library...
>
> (C:\Python22\Lib) $ grep " *del " *.py | wc
>      216     783    8643
>
> Hmm, 216 times.  I think it's safe to say that it's widely used. :-)
>

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

- Daniel




More information about the Python-list mailing list