[Tutor] Re: using IDLE and changing variables

Jesse W jessw@loop.com
Mon, 6 Aug 2001 16:35:57 -0700


Dear all,
	Whenever I see this thread again(and I have seen it often :-) ), I 
think to myself: "This does not look to hard to hack up, why don't I 
do it?"  Well, finally, I have.  Here it is:

-----------------------------------------------------------------------------
def reset(namespace, user_safe_items=()):
	"""Reset given namespace to a "pristine" state.

	This is a widely requested function which will remove from the
	current namespace everything execpt the items listed in
	below."""
	safe_items=['__builtins__', '__doc__', '__name__', 'reset']\
		    +list(user_safe_items)
	for item in namespace.keys():
		if item not in safe_items:
			exec "del "+item in namespace
-----------------------------------------------------------------------------
I expect (and hope) it is simple enough to be clear.

						Jesse F. W