[Tutor] Reset function

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 8 Aug 2001 10:39:18 -0700 (PDT)

On Wed, 8 Aug 2001, Christopher Smith wrote:

> Dear tutor,
> I looked at the reset function presented recently to "purify the namespace"
> before running a program (reset(vars())) and the last line has me stumped.
> Here's a simplified version: 
> ###
> def reset(namespace, user_safe_items=()):
> 	for item in namespace.keys():
> 		exec "del "+item in namespace

Try parsing it like this:

    exec ("del" + item)  in namespace

It might actually be better to write it like this to avoid confusion.  The
'in namespace' part is an optional part of the exec statement:


Good luck!