PythonWin: any way to delete all objects without exiting and without doing it with "del"?

Steven Bethard steven.bethard at gmail.com
Wed Mar 1 18:13:17 EST 2006


dananrg at yahoo.com wrote:
> In PythonWin, is there any way to bulk-delete all objects without using
> "del object" for each, and without having to exit out of PythonWin?

I think you just want to modify the globals() dict:

 >>> list(globals())
['__builtins__', 'text', 'glob', 'pywin', 're', 'match', 'basename', 
'__name__', 'line', 'foo', 'os', '__doc__', 'fn']
 >>> for name in list(globals()):
...     if name != 'pywin' and name[:2] != '__':
...         del globals()[name]
...
 >>> del name
 >>> list(globals())
['__builtins__', 'pywin', '__name__', '__doc__']

Be careful though, I think there's a few things in there you might not 
want to ``del`` (e.g. ``pywin``).

STeVe



More information about the Python-list mailing list