cleanup questions?
Terry Reedy
tjreedy at udel.edu
Sun Jan 26 16:21:35 EST 2003
"hénon" <meinrad.recheis at gmx.at> wrote in message
news:b11eg4$rt3$1 at news.tuwien.ac.at...
> hi, i have two questions:
>
> 1) How do i get a list of all existing (previously generated)
objects in the
> interpreters namespace?
> and is there a command to clean them all up?
By "interpreter's namespace" I presume you mean not the C namespace of
CPython, but the namespace of the currently executing __main__ module.
There is no such command (other than sys.exit(8-)). You have to
(carefully) delete one thing at a time:
# add something
a,b=1,2
dir()
#['__builtins__', '__doc__', '__name__', 'a', 'b']
import __main__
for w in dir():
if w not in ['__builtins__', '__name__', '__main__']:
delattr(__main__, w)
delattr(__main__, 'w')
delattr(__main__, '__main__')
dir()
#['__builtins__', '__name__']
# Assume __doc__ not really needed, but code may depend on these two.
Terry J. Reedy
More information about the Python-list
mailing list