Unbinding multiple variables

Stephen Thorne stephen.thorne at gmail.com
Thu Jan 20 22:37:14 EST 2005


On 20 Jan 2005 19:24:43 -0800, Johnny Lin <air_jlin at yahoo.com> wrote:
> Hi!
> 
> Is there a way to automate the unbinding of multiple variables?  Say I
> have a list of the names of all variables in the current scope via
> dir().  Is there a command using del or something like that that will
> iterate the list and unbind each of the variables?
> 
> Thanks much!  (If anyone posts an answer, if you could also cc your
> reply to my email air_jlin at yahoo.com, would be much obliged.  Thanks
> again!)

My immediate reaction is "You never want to do that"

If you're doing something along these lines:

#some code
#create lots of variables
#do stuff with those variables
# <want to delete variables here
#more code

Try converting it to this idiom:

def someFunction(someinput)
  #create lots of variables
  #do stuff with those variables
  return output

#some code
output = someFunction(input)
#more code

Regards,
Stephen Thorne.



More information about the Python-list mailing list