On Wed, 07 Dec 2005 10:59:09 +0100, Sybren Stuvel wrote: > Steven D'Aprano enlightened us with: >> All joking aside, when I have names (temporary variables or >> scaffolding functions) that I need to initialise a module or data >> structure, but then outlive their usefulness, I del the name >> afterwards. Am I the only one? > > I don't do that. I tend to split up my code into pretty small > functions, so the temporary names I use have a small scope as is. I > don't see the need to add extra 'del' commands when the 'return' five > lines further down is going to do the same.
But then you have all these small functions lying around in your module. If you intend to use them multiple times, then obviously you should keep them. But if they are intended to be used once, and once only, it seems bad to leave them there tempting fate. E.g. you have some code that uses a large lookup table. Rather than type the lookup table in by hand, you write a function which creates all or part of it. Once the lookup table is created, you shouldn't use that function again -- at best it is just sitting around like a third wheel, at worst it might have side-effects you don't want. So I del the function. The logic seems impeccable to me, and yet somehow deleting them after they are used feels ... not so much wrong, as just ... worthy of a head-scratching. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list