Clearing pythonwin environment

Scott David Daniels scott.daniels at acm.org
Fri Jun 23 21:48:07 CEST 2006


Network Ninja wrote:
> I want to restart the environment occasionally to default (like I
> restarted pythonwin). I wrote this script. I know why it doesn't work,
> cause it deletes my variable (item) on each iteration. My question is:
> is it possible to do this? What other things might I try?
> 
> keep = ['__builtins__', '__doc__', '__name__', 'pywin', 'keep', 'item']
> for item in dir():
>     if item not in keep:
>         del item

     keep = set(['__builtins__', '__doc__', '__name__',
                 'pywin', 'keep', 'item', 'globs'])  # Faster to test
     globs = globals()
     for item in dir():
         if item not in keep:
             del globs[item]
     del globs, item

Note that this leaves all imported modules imported.

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list