When (and why) to use del?

Albert Hopkins marduk at letterboxes.org
Tue Dec 9 17:35:17 CET 2008


I'm looking at a person's code and I see a lot of stuff like this:

        def myfunction():
            # do some stuff stuff
            my_string = function_that_returns_string()
            # do some stuff with my_string
            del my_string
            # do some other stuff
            return

and also

        def otherfunction():
            try:
                # some stuff
            except SomeException, e:
                # more stuff
                del e
            return


I think this looks ugly, but also does it not hurt performance by
preempting the gc?  My feeling is that this is a misuse of 'del'. Am I
wrong?  Is there any advantage of doing the above?





More information about the Python-list mailing list