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